android onclick onLongClick ontouch dispatchTouchEvent onInterceptTouchEvent
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的更多相关文章
- 关于dispatchTouchEvent, onInterceptTouchEvent, onTouchEvent的分发机制浅析
虽说这个问题不是很难...动动手就能看出答案...但是似乎不太容易理解...几次尝试把这个问题说明白....但是好像感觉说不明白....(顿时想起了那句话----说不明白就是自己还不明白! 我怎么可能 ...
- 使用属性android:onClick,出现异常NoSuchMethodException
在Activity中注册点击事件有两种方式,setOnClickListener或在xml中设置控件的android:onClick="gotoSecond"属性,在Activit ...
- android:onClick vs setOnClickListener
为Android Widgets添加点击事件处理函数又两种方法,一个是在Xml文件中添加onClick属性,然后在代码中添加对应的函数.另一个是直接在代码中添加setOnClickListener函数 ...
- Fragment中Button的android:onClick 无法监听相应
在Fragment的布局文件中,Button控件下添加android:onClick监听: 1.fragment_main.xml <RelativeLayout xmlns:android=& ...
- android:onclick属性
android:onclick属性设置点击时从上下文中调用指定的方法,此时给指定一个方法名.例如: xml中: <Button android:layout_width="wrap_c ...
- Xamarin.Android中使用android:onClick="xxx"属性
原文:Xamarin.Android中使用android:onClick="xxx"属性 在原生Android开发中,为一个View增加点击事件,有三种方式: 1.使用匿名对象 ( ...
- 通过在xml布局文件中设置android:onClick=""来实现组件单击事件
在布局中出现android:onClick=""语句: <Button android:id="@+id/call_button" android:onC ...
- android:onClick都做了什么
同步发表于 http://avenwu.net/viewinject/2015/01/28/android_onclick/ 相信大家都知道在layout里面可以给view写android:onCli ...
- android:onClick="xxx"
一般监听OnClickListener事件,我们都是通过Button button = (Button)findViewById(....); button.setOClickLisener....这 ...
随机推荐
- 有关Flash Player的内存管理及泄露检测
1.Flash Player分配内存的策略是少量请求大内存块, 也就是不会频繁向系统请求内存. 2.Flash Player内存的回收是根据引用计数和标记清除(比较耗cpu)这两种方法. 3.从理论上 ...
- 精简android4.2
cd /system/apprm YouTube.*rm Settings.*rm VoiceDialer.*rm Phone.*rm QuickSearchBox.*rm RSSReader.*rm ...
- astyle 使用说明
欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://github.com/jiangxincode 知乎地址 ...
- input上传图片预览
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- 025-ViewData、ViewBag与TempData概述
Action向View传递数据很简单,方式也很多,最直接的就是我们向View传递Model,这本身就是MVC的意义所在.如果是显示一些消息,像是错误信息,可以使用ViewData.ViewBag.Te ...
- 009-Selenium2环境搭建
1.Java开发环境的搭建 本课程中将使用Java语言编写Selenium自动化测试脚本,在Eclipse集成开发环境中运行. (1)jdk的安装 a.下载 官网下载,http://www. ...
- Python3学习笔记(urllib模块的使用)转http://www.cnblogs.com/Lands-ljk/p/5447127.html
Python3学习笔记(urllib模块的使用) 1.基本方法 urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, ...
- JavaWeb基础: 学习大纲
JavaWeb基础: Web应用和Web服务器 JavaWeb基础: Tomcat JavaWeb基础:HTTP协议和基于Restful的架构 JavaWeb基础: Web工程配置文件 JavaWeb ...
- Xcode8 及iOS10适配问题汇总
上点干货,目前得知的一些bug解决汇总:iOS10相册相机闪退bughttp://www.jianshu.com/p/5085430b029fiOS 10 因苹果健康导致闪退 crashhttp:// ...
- Error in Android Studio - "Default Activity Not Found"
Make sure you have specified the default activity in your AndroidManisfest.xml file. Within your def ...