OnTouchListener的活动永远不会调用

编程入门 行业动态 更新时间:2024-10-19 23:41:19
本文介绍了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的活动永远不会调用

本文发布于:2023-11-26 20:54:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635154.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:永远不会   OnTouchListener

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!