如何在Android中检测用户何时点击视图
我想在Android应用程序中检测用户何时点击视图中的任何位置 我的代码如下所示:如何在Android中检测用户何时点击视图,android,Android,我想在Android应用程序中检测用户何时点击视图中的任何位置 我的代码如下所示: linearLayout = (LinearLayout) findViewById(R.id.linearLayout); // main layout // ... linearLayout.setOnTouchListener(this); // ... public boolean onTouch(View v, MotionEvent event) { Toast.makeText(this,
linearLayout = (LinearLayout) findViewById(R.id.linearLayout); // main layout
// ...
linearLayout.setOnTouchListener(this);
// ...
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(this, "Touch!", 1000);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Toast.makeText(this, "Down!", 1000);
return true;
}
return false;
}
…但是当我点击视图时,我没有得到烤面包
触摸事件是否在模拟器中工作?或者我的代码中是否有错误?我认为问题在于您的消息显示代码而不是触摸检测代码 您正在创建
Toast
对象,但没有显示它。你需要打电话给警察
另外,duration
参数应为或之一
尝试:
我们都去过那里…不管怎样,我去过两次。我一直在寻找相同的解决方案。谢谢Biswajit
Toast.makeText(this, "Down!", Toast.LENGTH_LONG).show();