简体   繁体   English

父级LinearLayout onclick,未从子级recyclerview中调用

[英]Parent LinearLayout onclick, not called from child recyclerview

I have a linear layout, with many children views, including a recyclerview. 我有一个线性布局,有很多子视图,包括recyclerview。 I want the entire parent view to be clickable, and when the chidren are clicked I want the same thing to happen. 我希望整个父视图都是可单击的,当单击孩子时,我希望发生同样的事情。 ie I want that where ever you click in the parent view, the method will be called. 即我希望无论您在父视图中单击什么位置,都将调用该方法。

Now this is working fine, and whenever you click in the parent the method is called. 现在,这可以正常工作,每当您单击父级时,都会调用该方法。 Except the recycler view, that when I click there, nothing happens. 除了回收者视图,当我单击那里时,什么也没有发生。 I tried setting clickable and focusable of the recyclerview view to true and false, and it still didn't work. 我尝试将recyclerview视图的clickable和focusable设置为true和false,但仍然无法正常工作。

Here is my xml: 这是我的xml:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="onTodayMainPageClick"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="@drawable/date_background"
    android:orientation="vertical"
    android:padding="10dp">

    <TextView
        android:id="@+id/date_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:layout_gravity="center"
        android:text="1st October 2017"
        android:layout_marginBottom="10dp"/>


    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorPrimary"/>


    <TextView
        android:id="@+id/whats_left_for_today_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"

        android:text="Whats left for today"
        android:textColor="@color/colorPrimary" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/today_recycler_view_summary"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusable="true"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp">

    </android.support.v7.widget.RecyclerView>



</LinearLayout>

Thanks 谢谢

You should try doing it in following way, 您应该尝试按以下方式进行操作,

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear_main"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:orientation="vertical"
    android:padding="10dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">

    <TextView
        android:id="@+id/date_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="10dp"
        android:text="1st October 2017"
        android:textColor="@color/colorPrimary" />


    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorPrimary" />


    <TextView
        android:id="@+id/whats_left_for_today_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"

        android:text="Whats left for today"
        android:textColor="@color/colorPrimary" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/today_recycler_view_summary"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="#eee"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp">

    </android.support.v7.widget.RecyclerView>

</LinearLayout>

<View
    android:id="@+id/clickable_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="@+id/linear_main"
    android:clickable="true"
    android:onClick="onTodayMainPageClick"
    app:layout_constraintLeft_toLeftOf="@+id/linear_main"
    app:layout_constraintRight_toRightOf="@+id/linear_main"
    app:layout_constraintTop_toTopOf="@+id/linear_main" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改子LinearLayout可见性“onClick”内部LinearLayout内的TextView - Change child LinearLayout visibility “onClick” ing a TextView inside parent LinearLayout onClick 未在带有子项的 LinearLayout 上触发 - onClick not triggered on LinearLayout with child 从子 RecyclerView 更新父 RecyclerView 中的值 - Updating Values in Parent RecyclerView from a Child RecyclerView onClick 不适用于带有子 Switch 的 LinearLayout - onClick not work on LinearLayout with child Switch 没有调用RecyclerView Adapter OnClick - RecyclerView Adapter OnClick not Called 在LinearLayout中以编程方式添加视图的RecyclerView ViewHolder给出错误“您必须首先在孩子的父级上调用removeView()” - RecyclerView ViewHolder with programmatically added views in LinearLayout gives error “You must call removeView() on the child's parent first” 用LinearLayout子级填充RelativeLayout父级 - Fill RelativeLayout parent with LinearLayout child 如何从其子 recyclerview 视图中获取父 recyclerview 的引用? - How to get reference of the parent recyclerview from its child recyclerview views? 布局未从LinearLayout中的RecyclerView刷新 - Layout not refreshing from RecyclerView in LinearLayout 停止android scrollview防止父LinearLayout onclick - Stop android scrollview prevent parent LinearLayout onclick
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM