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. 笔记3:关于VBS整人代码的浅谈

    今天又看到有人在群里刷屏了.就想到了以前玩过的发QQ骚扰信息程序了.其实蛮简单的 和网上很多的整人代码差不多 一.直接在网上搜索“VBS整人代码”,然后找到有用的代码复制着. ps:在网上有很多有意思 ...

  2. [转]ebkit内核浏览器的Linear Gradients (线性渐变)

    转自:http://www.css88.com/archives/tag/webkit-gradient webkit内核的safari. Chrome的Linear Gradients (线性渐变) ...

  3. hdu----(1257)最少拦截系统(dp/LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. MessageDigest简介

    一.概述 MessageDigest 类为应用程序提供信息摘要算法的功能,如 MD5 或 SHA 算法.信息摘要是安全的单向哈希函数,它接收任意大小的数据,并输出固定长度的哈希值. MessageDi ...

  5. while、do while练习——7月24日

    while循环的格式是for循环的变形 //while 循环(当循环),是for循环的变形 //for(int i=0;i<=5;i++) //{ // Console.WriteLine(&q ...

  6. 【转】Session ID/session token 及和cookie区别

    Session + Cookie  知识收集! cookie机制采用的是在客户端保持状态的方案.它是在用户端的会话状态的存贮机制,他需要用户打开客户端的cookie支持.cookie的作用就是为了解决 ...

  7. input 中的enabled与disabled属性

    <style type="text/css"> *{ padding:; margin:; list-style-type: none; box-sizing:bord ...

  8. 修改weblogic PermGen

    vim /weblogic/Oracle/Middleware/wlserver_10.3/common/bin/commEnv.sh 在第144行,增加环境变量:JAVA_VENDOR=Sun #根 ...

  9. WPF TreeView的使用

    WPF提供了treeView控件,利用该控件开发者可以将数据分层显示在树结构中.当然其中需要用到Binding的机制,有用的类包括:ObjectDataProvider.DataTemplate.Hi ...

  10. CentOS Hadoop格式化HDFS异常java.net.UnknownHostException

    #bin/hadoop namenode -format DEPRECATED: Use of this script to execute hdfs command is deprecated. I ...