android onclick onLongClick ontouch dispatchTouchEvent onInterceptTouchEvent

按ACTION_DOWN -> onLongClick -> ACTION_UP -> onClick的次序发生的

onTouchevent() vs onTouch()

onTouch() is used by users of the View to get touch events while onTouchEvent() is used by derived classes of the View to get touch events.

1) Implementation:

If you want use onTouch() you have to do three things.

1- implement OnTouchListener

2- call setOnTouchListener() on the view you want to set catch the event

3- override onTouch() to handle the event

but if you want to use onTouchEvent() you don't need to do step 1 & 2 above. just you need to override onTouchEvent().

2) Working:

onTouch() works on view, viewgroup, activity. Meaning you can use onTouch() inside view, viewgroup or activity. This methods take two arguments [onTouch(View v, MotionEvent e) ]. This allows you filter events for different views in an activity or view group. Or the activity can itself handle it. onTouchEvent() takes on one argument [onTouchEvent(MotionEvent e) ]. Thus this can be used only inside the view that implements it or on the derived view.

I think, such options are part of Android's more flexible development philosophy, though it creates confusion for the learners at times.

android onclick onLongClick ontouch dispatchTouchEvent onInterceptTouchEvent的更多相关文章

  1. 关于dispatchTouchEvent, onInterceptTouchEvent, onTouchEvent的分发机制浅析

    虽说这个问题不是很难...动动手就能看出答案...但是似乎不太容易理解...几次尝试把这个问题说明白....但是好像感觉说不明白....(顿时想起了那句话----说不明白就是自己还不明白! 我怎么可能 ...

  2. 使用属性android:onClick,出现异常NoSuchMethodException

    在Activity中注册点击事件有两种方式,setOnClickListener或在xml中设置控件的android:onClick="gotoSecond"属性,在Activit ...

  3. android:onClick vs setOnClickListener

    为Android Widgets添加点击事件处理函数又两种方法,一个是在Xml文件中添加onClick属性,然后在代码中添加对应的函数.另一个是直接在代码中添加setOnClickListener函数 ...

  4. Fragment中Button的android:onClick 无法监听相应

    在Fragment的布局文件中,Button控件下添加android:onClick监听: 1.fragment_main.xml <RelativeLayout xmlns:android=& ...

  5. android:onclick属性

    android:onclick属性设置点击时从上下文中调用指定的方法,此时给指定一个方法名.例如: xml中: <Button android:layout_width="wrap_c ...

  6. Xamarin.Android中使用android:onClick="xxx"属性

    原文:Xamarin.Android中使用android:onClick="xxx"属性 在原生Android开发中,为一个View增加点击事件,有三种方式: 1.使用匿名对象 ( ...

  7. 通过在xml布局文件中设置android:onClick=""来实现组件单击事件

    在布局中出现android:onClick=""语句: <Button android:id="@+id/call_button" android:onC ...

  8. android:onClick都做了什么

    同步发表于 http://avenwu.net/viewinject/2015/01/28/android_onclick/ 相信大家都知道在layout里面可以给view写android:onCli ...

  9. android:onClick="xxx"

    一般监听OnClickListener事件,我们都是通过Button button = (Button)findViewById(....); button.setOClickLisener....这 ...

随机推荐

  1. 创建和使用Windows静态链接库

    首先明确这篇文章的目的,我希望大家能够通过这篇文章了解一下如何在实际工作中创建和使用Windows平台下的静态链接库.关于链接库的概念,希望大家参考维基百科"Library"词条( ...

  2. fushioncharts的使用教程

    FusionCharts 是使用javascript 实现统计图表的js组件:其官网地址:http://www.fusioncharts.com.其早期版本FusionCharts Free 是基于f ...

  3. 栅栏 CyclicBarrier

    java.util.concurrent.CyclicBarrier 类是一种同步机制,它能够对处理一些算法的线程实现同步.换句话讲,它就是一个所有线程必须等待的一个栅栏,直到所有线程都到达这里,然后 ...

  4. VBA中四种自动运行的宏以及模块的含义

    在Excel的“标准模块”中可以创建4种自动运行的宏,它们分别是Auto_Open(打开工作 簿时自动运行), Auto_Close, Auto_Activate,  Auto_Deactivate. ...

  5. 安装 request模块

    python3 requests 安装包下载安装[windows] 听语音 | 浏览:54 | 更新:2016-07-25 17:09 windows下直接使用:easy_install reques ...

  6. 为大家分享一个 Ajax Loading —— spin.js(转)

    原文地址:http://www.cnblogs.com/lxblog/p/3425599.html 我们在做Ajax 异步请求的时候,一般都会利用一个动态的 Gif 小图片来制作一个Ajax Load ...

  7. Extjs 视频教程

    ---恢复内容开始--- 网易云课堂 <尚学堂_Ext视频教程> login.html <html> <head> <meta http-equiv=&quo ...

  8. word-wrap word-break white-space 用法。

    一.word-wrap使用: 语法: word-wrap : normal | break-word 取值说明: 1.normal和break-word,其中normal为默认值,当其值为normal ...

  9. HTTP方法简介

    GET 请求获取资源 HEAD 与GET类似,但服务器只返回首部 PUT 与GET相反,向服务器写入文档 POST 向服务器输入数据,通常使用HTML表单形式 TRACE 客户端发起请求时,需要穿越防 ...

  10. [转]Java程序员们最常犯的10个错误

    1.将数组转化为列表 将数组转化为一个列表时,程序员们经常这样做: List<String> list = Arrays.asList(arr); Arrays.asList()会返回一个 ...