如何触发列表视图正确Longclick事件 [英] how to trigger proper Longclick event on listview

查看:179
本文介绍了如何触发列表视图正确Longclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示在列表视图中长preSS的Andr​​oid语境动作模式
但是当我们渴望preSS那么多的一些事件触发和上下文菜单隐藏
那么有没有办法来处理这​​个问题。

i have to show Android Contextual action mode on long press of list view but when we long press then some multiple event trigger and Contextual menu hide so is there way to handle this problems.

我也尝试onLongClick()返回true,但它不工作

i also try return true on onLongClick() but its not working

在此先感谢您的帮助。

推荐答案

在计算器搜索后
我发现我的答案使用此问题
在我的列表视图实现GestureDetector的这里是我的code

After search on stackoverflow i found my answer using this question implement GestureDetector on my listview an here is my code

在列表视图设置GestureDetector

set GestureDetector on listview

final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector());
        View.OnTouchListener gestureListener = new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event); 
            }};
        mMessageListView.setOnTouchListener(gestureListener);

和MyGestureDetector这个code

and this code of MyGestureDetector

class MyGestureDetector extends SimpleOnGestureListener{ 

           @Override
        public void onLongPress(MotionEvent e) {
            super.onLongPress(e);
            ListView lv = mMessageListView;
            int pos = lv.pointToPosition((int)e.getX(), (int)e.getY());
            if (listMsg.get(pos).type==ChatItem.ITEM) {
                mMessageListView.setItemChecked(pos, !adapter.isPositionChecked(pos));
            } 
        }

       }

我分享这个答案,以便它可以为其他有用的份额

i share this ans so it can helpful for other share

这篇关于如何触发列表视图正确Longclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆