ListView重写onTouch后不能滚动列表问题

设置一个ListView的OnTouch监听事件并重写OnTouch函数,代码如下:

       mSingleListView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    mHandler.removeMessages(MSG_CHLIST_SLIDE_OUT);
                    break;
                case MotionEvent.ACTION_UP:
                    mHandler.sendEmptyMessageDelayed(MSG_CHLIST_SLIDE_OUT, TIME_DELAY_CHLIST_SLIDE_OUT);
                    break;
                default:
                    break;
                }
                return true;
            }

        });

重写运行程序发现ListView中的内容无法滚动显示,查资料发现需要将reture true改为reture false之后就能正常的操作显示列表,这里说明下return true/false的区别,查看OnTouch函数说明:

public abstract boolean onTouch (View v, MotionEvent event)
Added in API level 1

Called when a touch event is dispatched to a view. This allows listeners to get a chance to respond before the target view.

Parameters
vThe view the touch event has been dispatched to.
eventThe MotionEvent object containing full information about the event.
Returns
  • True if the listener has consumed the event, false otherwise.
当return true时表示event已被“消费”,这就意味着这个event不会再发送给其它方法,如果返回false则表示这个OnTouch方法中未处理该事件,系统需要查找下一个事件进行处理。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值