GridView长按短按冲突

来源:互联网 发布:centos 安装lamp环境 编辑:程序博客网 时间:2024/06/01 23:28
在项目中为GridView设置长按和短按监听时,会出现短按正常,但是长按时会先执行长按,然后再执行短按,这就造成了长按时与短按监听冲突。查看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         *         * @return true if the callback consumed the long click, false otherwise         */        boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id);
发现这么一句注释**@return true if the callback consumed the long click, false otherwise**,如果回调消耗了长时间单击,则返回true,否则为false,那么在OnItemLongClickListener的最后将return false改为return ture,就解决了长按与短按的冲突。
原创粉丝点击