问题
I have many views (FrameLayouts) on my screen - each has a SimpleOnGestureListener set as the onTouchListener.
I'm correctly getting the onSingleTapConfirmed method being fired when I tap one of these views, but I can't work out how to determine which view was tapped?
Is there a simple way to do this from the MotionEvent?
回答1:
I have many views (FrameLayouts) on my screen - each has a SimpleOnGestureListener set as the onTouchListener.
Save a reference to the View in the OnTouchListener, then when a gesture callback fires you'll already know which View was touched:
public boolean onTouch(View v, MotionEvent event) {
// Remember which View was touched
mCurrent = v;
// Pass event to gesture listener, etc
}
Now use mCurrent
in onSingleTapConfirmed()
and any other method.
来源:https://stackoverflow.com/questions/15070386/detect-which-view-was-tapped-in-the-onsingletapconfirmed-method