I am trying to customize a gridview of buttons that respond to onTouch. For example, if I swipe the screen horizontally, vertically or diagonally, I want the buttons that have been touched to be selected. I tried setting OnTouchListener for the buttons, but that did not work, only the first button in the drag event received onTouch events.
Next, I tried to create an OnTouchListener for the GridView, and then using the X, Y codes to determine which buttons are touching. This does not seem to work, since the MOTION_DOWN events are only dispatched to the GridView onTouch () if I start dragging along the very edge of the GridView. In fact, if I drag my finger horizontally across the grid, the onTouch events do not fire at all, unless I started dragging along the edge of the GridView. Does anyone know how best to do this?
Thanks in advance.
gridview.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(@SuppressWarnings("unused") View view, MotionEvent event)
{
float X = event.getX();
float Y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
System.out.println("Down: " + X + "," + Y);
break;
case MotionEvent.ACTION_MOVE:
System.out.println("Move: " + X + "," + Y);
break;
case MotionEvent.ACTION_UP:
System.out.println("Up: " + X + "," + Y);
break;
}
return true;
}
}
Jeff source
share