2017-12-09 24 views
0

リサイクルビューを含む多くの子ビューを持つ線形レイアウトです。 親ビュー全体をクリック可能にして、子供がクリックされたときに同じことが起こりたいと思います。つまり、親ビューでクリックした場所をクリックすると、そのメソッドが呼び出されます。親LinearLayout onclick、子リサイクルビューから呼び出されていない

これはうまくいきました。親をクリックするたびにメソッドが呼び出されます。リサイクラーのビューを除いて、そこをクリックすると何も起こりません。私は、リクリスタルビューのclickableとfocusableをtrueとfalseに設定しようとしましたが、それでも動作しませんでした。ここで

は私の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> 

おかげ

あなたは、以下の方法でそれをやってみてください

答えて

0

<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" /> 

関連する問題