Android长按事件和点击事件问题处理,OnItemLongClickListener和OnItemClickListener冲突问题
今天在做demo时,须要设置ListView的item的长按和点击事件。OnItemLongClickListener和OnItemClickListener,然而点击事件能够实现,可是在长按操作时会同一时候触发点击事件(长按和点击冲突),然后查看了一下Android的相关源代码,能够看到系统是优先对应clicklisener的,他是没有返回值的的。而对于OnItemLongClickListener是有一个返回值标识。
对于一次长按操作。假设返回false,则2个lisener都会对应,假设返回true则系统仅仅处理长按事件。
因此。想要自己的OnItemLongClickListener长按事件生效,须要将返回值设为true。
以下是源代码
/**
* Interface definition for a callback to be invoked when an item in this
* AdapterView has been clicked.
*/
public interface OnItemClickListener { /**
* Callback method to be invoked when an item in this AdapterView has
* been clicked.
* <p>
* Implementers can call getItemAtPosition(position) if they need
* to access the data associated with the selected item.
*
* @param parent The AdapterView where the click happened.
* @param view The view within the AdapterView that was clicked (this
* will be a view provided by the adapter)
* @param position The position of the view in the adapter.
* @param id The row id of the item that was clicked.
*/
void onItemClick(AdapterView<?> parent, View view, int position, long id);
}
/**
* Interface definition for a callback to be invoked when an item in this
* view has been clicked and held.
*/
public interface OnItemLongClickListener {
/**
* Callback method to be invoked when an item in this view has been
* clicked and held.
*
* Implementers can call getItemAtPosition(position) if they need to access
* the data associated with the selected item.
*
* @param parent The AbsListView where the click happened
* @param view The view within the AbsListView that was clicked
* @param position The position of the view in the list
* @param id The row id of the item that was clicked
* 源代码这里已经给出解释。假设返回值设为true。则系统消耗掉长按事件
* @return true if the callback consumed the long click, false otherwise
*/
boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id);
}
Android长按事件和点击事件问题处理,OnItemLongClickListener和OnItemClickListener冲突问题的更多相关文章
- Android监听消息通知栏点击事件
Android监听消息通知栏点击事件 使用BroadCastReceiver 1 新建一个NotificationClickReceiver 类,并且在清单文件中注册!! public class N ...
- [前端][自定义DOM事件]不使用setTimeout实现双击事件或n击事件
使用setTimeout实现双击事件 例如,这样: let div = document.getElementById("div"); doubleClick(div, funct ...
- JS怎样将拖拉事件与点击事件分离?
帖子:http://bbs.csdn.net/topics/390785395?page=1#post-397369340 怎样将拖拉事件跟点击事件分离? 须要做到:拖拉时不触动点击事件 <ht ...
- (网页)HTML5 Canvas ( 事件交互, 点击事件为例 ) isPointInPath(转)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- HTML5 Canvas ( 事件交互, 点击事件为例 ) isPointInPath
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Android长按事件和点击事件 冲突问题
长按点击的时候默认会触发点击事件,android系统是优先点击的,并且没有返回值:而长按事件是有返回值的,如果返回false,两个事件都会有响应,如果返回true则只响应长按事件.
- Android菜鸟成长记4-button点击事件
Button 1.button按钮的创建 一般来说,在我们新建一个Android项目的时候,会有会默认有一个activity_main.xml的文件 如果你在新建项目的时候,把Create Activ ...
- Android按钮的四种点击事件
本文记录一下按钮的四种点击事件 第一种 public class MainActivity extends Activity { @Override protected void onCreate(B ...
- 【转】Android - Button(按钮)的响应点击事件的4种写法
原文网址:http://www.yrom.net/blog/2011/12/12/android-4-onclicklistener-of-button/ Button控件setOnclickList ...
随机推荐
- jQuery_事件学习
一.click事件 click事件----鼠标单击事件 $('.bt').click(function() { alert("本身的事件");}) 当class为bt的div被但单 ...
- 一起写框架-Ioc内核容器的实现-基础功能-ComponentScan支持多包扫描(六)
实现功能 1.我们看到@ComponentScan注解一个开始定义就是需要支持,扫描多个包,将多个包的类名获取到.现在就实现这个功能. 实现思路 根据传入的字符串数组,获得多个包下的类全限制名. 实现 ...
- 身为运维的你,怎么掌握python才不会失业
以前,我们都说Python是运维工程师的未来:现在,为什么大家都说不会Python的运维都将失业?运维必须懂开发,特别是python开发,已经形成大家的共识,不懂开发的运维,路会越走越窄. 而现在的情 ...
- C#中的静态成员和非静态成员
C#的类中可以包含两种方法:C#静态方法与非静态方法.那么他们的定义有什么不同呢?他们在使用上会有什么不同呢? 让我们来看看最直观的差别:使用了static 修饰符的方法为静态方法,反之则是非静态方法 ...
- CodeRush Xpress的菜单在VS2008SP1中不显示的解决方法
将HKEY_LOCAL_MACHINE\SOFTWARE\Developer Express\CodeRush for VS\9.1中的HideMenu设置为0.若HideMenu不存在就创建个DWO ...
- 制作代码模板的 LaTex 模板
Tex 真的是一个用起来非常舒服的排版工具(对于排版要求高的人来说),去比赛前一天放弃了markdown转pdf来生成代码模板,现学Tex(其实美赛已经用过了:P). 推荐一个链接:TeX - Bea ...
- react 体验 react与vue的比较
用了 vue 大半年了,不过我在2016年暑假的时候就看到了 react 这个项目,有点想学习一番,之前学习的都是基础语法和一些基础用法吧,总的来说 mvvm 框架确实都很相似,会一个就可以了; 今天 ...
- 书籍推荐系列之一 -- 《凤凰项目:一个IT运维的传奇故事》
博客已经完全更新了名字,新的名字,新的开始,想让自走向新的道路是很难的,走出舒适圈说了好久,也是时候开始行动了,今天就从写博客开始. 今天给大家推荐一本书,<凤凰项目:一个IT运维的传奇故事&g ...
- TFboy养成记 tensorboard
首先介绍几个用法: with tf.name_scope(name = "inputs"): 这个是用于区分区域的.如,train,inputs等. xs = tf.placeho ...
- 02-线性结构4 Pop Sequence
题目 Sample Input: 5 7 5 1 2 3 4 5 6 7 3 2 1 7 5 6 4 7 6 5 4 3 2 1 5 6 4 3 7 2 1 1 7 6 5 4 3 2 Sample ...