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....这 ...
随机推荐
- ma
首页 第一项 上课 哈哈
- 布局两列div等高方法
一.左右布局,左侧div绝对定位,外div相对定位 <!DOCTYPE html> <html lang="en"> <head> <me ...
- 面试时,问哪些问题能试出一个 Android 应用开发者真正的水平?【转自知乎】
这几年面过的各种Android开发也有三位数了,failed的不敢说,pass的基本都没有看走眼,来得晚了也想说说我的体会. 一般面试时间短则30分钟,多则1个小时,这么点时间要全面考察一个人难度很大 ...
- Qt之Concurrent Map和Map-Reduce
简述 QtConcurrent::map().QtConcurrent::mapped()和QtConcurrent::mappedReduced()函数在一个序列中(例如:QList或QVector ...
- Qt之属性系统
简述 Qt提供一个类似于其它编译器供应商提供的复杂属性系统(Property System).然而,作为一个编译器和平台无关的库,Qt不能够依赖于那些非标准的编译器特性,比如:__property或者 ...
- Spring Data Jpa配置
Spring Data JPA提供的接口,也是Spring Data JPA的核心概念: 1:Repository:最顶层的接口,是一个空的接口,目的是为了统一所有Repository的类型,且能让组 ...
- IKAnalyzer进行中文分词和去停用词
最近学习主题模型pLSA.LDA,就想拿来试试中文.首先就是找文本进行切词.去停用词等预处理,这里我找了开源工具IKAnalyzer2012,下载地址:(:(注意:这里尽量下载最新版本,我这里用的IK ...
- java 分析方法调用过程
StackTraceElement[] s = new Exception().getStackTrace(); for(int i=0;i<s.length;i++) System.out.p ...
- YanYan Self Introduction
My Website: http://finehappy.com/
- Axis2 webservice 之使用java调用webservice
在上一篇中写了一个简单了webservice,实现了一个sayHello功能.那么webservice写好之后我们如何使用Java程序来调用webservice呢? 一.java调用的webservi ...