Detect which View was tapped in the onSingleTapConfirmed method

旧巷老猫 提交于 2019-12-12 03:46:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!