作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 RelativeLayout 中有一个 ListView 。我希望对 ListView 的任何点击都可以调用 Relativelayout 的 onClick 监听器。 ListView 如何将其点击事件传递给父 View 。
我试过这个不行。
listView.setOnTouchListener(new OnTouchListener() {
// Setting on Touch Listener for handling the touch inside
// ScrollView
@Override
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of
// child view
listView.requestDisallowInterceptTouchEvent(false);
return false;
}
});
最佳答案
我认为您需要使用其中一种方法,以便能够在事件发送到适当的组件之前拦截该事件:
Activity.dispatchTouchEvent(MotionEvent)
- 这允许您的 Activity 在将所有触摸事件发送到窗口之前拦截它们。
ViewGroup.onInterceptTouchEvent(MotionEvent)
- 这允许 ViewGroup 在将事件分派(dispatch)给 subview 时观察事件。
ViewParent.requestDisallowInterceptTouchEvent(boolean)
- 在父 View 上调用它以指示它不应使用 onInterceptTouchEvent(MotionEvent) 拦截触摸事件。'
引用请点击此处EventHandlers
关于android - 如何将 listview 的 onClick 事件传递给父 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21982853/
我是一名优秀的程序员,十分优秀!