OnTouchListener的活动永远不会调用 [英] OnTouchListener on Activity never calls
本文介绍了OnTouchListener的活动永远不会调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这个code,但是当我点击活动在运行时,它永远不会命中OnTouch()方法。有人能指导我什么,我做错了什么?如果我需要的setContentView这项活动的?其实我想活动的坐标在哪里执行过程中用户的触摸。
公共类TouchTestAppActivity扩展活动实现OnTouchListener
{
@覆盖
公共无效的onCreate(包savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.touch);
}
@覆盖
公共布尔onTouch(查看为arg0,MotionEvent ARG1)
{
// TODO自动生成方法存根
字符串测试=你好;
}
}
解决方案
更新:
您需要做的:
- 在XML布局文件,你需要的根视图的ID:
机器人:ID =@ + ID / MyView的
-
在十有二的onCreate()方法,这样写:
LinearView V =(LinearView)findViewById(R.id.myView); v.setOnTouchListener(本);
假设你的根视图是一个 LinearView
I used this code, but when i click on activity at runtime, it never hits in OnTouch() method. Can someone guide me what i am doing wrong? Should i need to setcontentview of this activity? Actually i want the coordinates of activity where user touch during execution.
public class TouchTestAppActivity extends Activity implements OnTouchListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.touch);
}
@Override
public boolean onTouch(View arg0, MotionEvent arg1)
{
// TODO Auto-generated method stub
String test = "hello";
}
}
解决方案
UPDATE:
You need to do this :
- In your XML layout file, you need an ID for the root view:
android:id="@+id/myView"
In youer onCreate() method, write this:
LinearView v= (LinearView) findViewById(R.id.myView); v.setOnTouchListener(this);
Assuming that your root view is a LinearView
这篇关于OnTouchListener的活动永远不会调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文