Android detects button hover in GridView

I have a GridView with 6 buttons, and I need to determine which button the user is currently using, finger vibrate when the user reaches the edge of a specific button. Is it possible to do this on the button layer in the GridView or is it better to implement it in my gridview and count the coordinates of each edge of the button?

+5
source share
1 answer

You can define your own OnTouchListener to capture events received by the View in the GridView. Something like that:

View.OnTouchListener listener = new View.OnTouchListener {
    public void onTouch ( View v, MotionEvent event ) {
        /** Check the event and the View here */
        return false; // Return false, so the system will behave as always
    }
}

public View getView ( int position, View v, ViewGroup vg ) {
    /** Create your View here */
    v.setOnTouchListener ( listener );

    /**
      Maybe you could need this too
      vg.setOnTouchListener ( listener ); 
    */
    return v;
}
0
source

All Articles