Android 如何将listview onClick事件传递给父视图

Android 如何将listview onClick事件传递给父视图,android,android-listview,Android,Android Listview,我在RelativeLayout中有一个列表视图。我希望单击listview调用Relativelayout的onClick侦听器。listview如何将其单击事件传递给父视图 我试过了,但没用 listView.setOnTouchListener(new OnTouchListener() { // Setting on Touch Listener for handling the touch inside // ScrollView @Ov

我在RelativeLayout中有一个列表视图。我希望单击listview调用Relativelayout的onClick侦听器。listview如何将其单击事件传递给父视图

我试过了,但没用

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;
        }

    });

我认为您需要使用其中一种方法,以便能够在事件发送到适当的组件之前拦截事件:

活动。dispatchTouchEvent(MotionEvent)
-这允许您的活动在将所有触摸事件发送到窗口之前拦截它们

ViewGroup.onInterceptTouchEvent(MotionEvent)
-这允许视图组在将事件分派到子视图时查看事件

ViewParent.RequestDisallowWinterCeptTouchEvent(布尔值)
-在父视图上调用此函数,以指示它不应使用onInterceptTouchEvent(MotionEvent)截获触摸事件

如需参考,请查看此处

可在XML中使用:

 android:focusable="false"
在java代码使用中:

 v.setClickable(false)