如何检测的Android用户触摸互动? [英] How detect user touch interaction in android?
问题描述
在我的活动有动作条,ListView中,文本菜单,菜单
。
我想捕捉用户的互动与我的活动(指当我的活动日益用户的触摸我想表现敬酒)。我用这个
I wanted to capture the user interaction with my activity(means when ever user touch in my activity i wanted to show a toast).I use this
@Override
public void onUserInteraction()
{
Toast.makeText(this, "Hello",Toast.LENGTH_LONG).show();
}
这个方法在屏幕上,但问题正在用这种方法它不工作与
This method working with in screen but problem with this method its not working with
菜单,文本菜单(ListView控件)
。
工作方案: - 1,这是工作的第一次,当我触摸屏幕,每一个地方的活动(动作条,ListView控件)。
Working Scenario:- 1-This is working first time when i touch the screen Every where in activity (ActionBar,ListView).
2,在点击菜单
第一次这个方法被调用,如果菜单
是有关的活动(如果我想继续下一个活动),它工作正常,但在相同的活性菜单
刷新
,我不知道为什么这种方法不调用点击刷新
。
2-After clicking the Menus
first time this method is calling and if the Menu
is related to activity (if i want to go on next activity ) it is working fine but there is a Menu
REFRESH
in same activity ,i do not know why this method not calling on clicking on REFRESH
.
3的同样的问题,文本菜单
(来后长preSS对的ListView
)
3- The same problem with ContextMenu
(comes after long press on ListView
)
我试过 GestureDetecter
也。
有一个在Android的任何特定方法或任何东西,它可以在菜单,文本菜单,列表,屏幕或每一个地方每一次检测用户触摸。
很多感谢的
推荐答案
我觉得你可以在你的活动覆盖dispatchTouchEvent()来得到你想要的结果。
I think you can override dispatchTouchEvent() in your Activity to get the result you want
是这样的:
@Override
public boolean dispatchTouchEvent(MotionEvent me){
//do something
return super.dispatchTouchEvent(me);
}
<一个href="https://developer.android.com/reference/android/app/Activity.html#dispatchTouchEvent%28android.view.MotionEvent%29"相对=nofollow>查看活动文档更多的
此外,我认为这是值得一提的是,您的用户可能会觉得很烦人,如果你是一个显示他们举杯碰任何东西在屏幕上的任何时间。
Also I think it is worth noting that your users may find it quite annoying if you are displaying a toast any time they touch anything on the screen.
这篇关于如何检测的Android用户触摸互动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!