How to prevent OnItemClickListener work when long click performed?

一个人想着一个人 提交于 2019-12-12 09:33:53

问题


I have a gridview and i want its items to act different if user performs click or long click that is why i am using OnItemClickListener and OnItemLongClickListener but when long click happens both listeners react.I want to perform only OnItemLongClickListener.


回答1:


public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {   
   return true;
}

return true will be prevent click event to be continue. It will be perform only OnItemLongClickListener.




回答2:


You can use AdapterView.setOnItemLongClickListener. GridView inherits AdapterView, so you can invoke that method on GridView too.




回答3:


In order to intercept long cliks (aka tapping) you should imlement GestureDetector.OnGestureListener



来源:https://stackoverflow.com/questions/3950211/how-to-prevent-onitemclicklistener-work-when-long-click-performed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!