I have a class extends ViewGroup and want to get every MotionEvent from it. So far I have this:
class TestViewGroup extends ViewGroup {
public TestViewGroup(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d("TestViewGroup", "X: " + (int)event.getX() + " Y: " + (int)event.getY());
return true;
}
}
The onTouchEvent(MotionEvent event) method is able to capture a MotionEvent every time I place my finger on the screen. But if I move my finger around the screen while my finger is still down, it won’t continue to trace the coordinates of my finger. I know that in a class that extends a View, it is possible to keep tracing the finger as it moves through the View. I’m just wondering how it is possible to apply the same idea to a ViewGroup.
I implemented a very simple ViewGroup class and copied your code, the onTouchEvent worked fine
The only thing I did differently was implement all of the constructors, though in general I would also call the super for the onTochEvent class that did not seem to make a difference.
So I am wondering if there is any code/xml you are leaving out that might make a difference?
Captures all touch events in emulator and on device, pretty much just like yours with the exception of the constructors.