检测哪些观的onSingleTapConfirmed方法被窃听 [英] Detect which View was tapped in the onSingleTapConfirmed method
问题描述
我有我的屏幕上的很多看法(FrameLayouts) - 每个人都有一个SimpleOnGestureListener设置为onTouchListener
我得到正确的时候我点击这些视图中的一个被解雇的onSingleTapConfirmed方法,但我不能工作,如何确定哪些视图被窃听?
有一个简单的方法来从MotionEvent?
做到这一点
我有我的屏幕上的很多看法(FrameLayouts) - 每个人都有一个SimpleOnGestureListener设置为onTouchListener
块引用>保存在OnTouchListener视图的引用,那么当一个手势回调触发你已经知道哪些浏览被感动了:
公共布尔onTouch(视图V,MotionEvent事件){
//记住这观点是感动
mCurrent = V; //传递事件的姿态监听器,等
}现在使用
mCurrent
在onSingleTapConfirmed()
和任何其他方法。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?
解决方案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
inonSingleTapConfirmed()
and any other method.这篇关于检测哪些观的onSingleTapConfirmed方法被窃听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!