gpt4 book ai didi

android - 如何将 listview 的 onClick 事件传递给父 View

转载 作者:太空狗 更新时间:2023-10-29 15:05:59 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com