设置一个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
v | The view the touch event has been dispatched to. |
---|---|
event | The MotionEvent object containing full information about the event. |
Returns
- True if the listener has consumed the event, false otherwise.