Ich habe eine RecyclerView, die in einem CardView ist, die ein paar TextViews hat. Die CardView hat einen OnClickListener
Satz und wird beim Klicken auf die TextViews abgefeuert, aber nicht beim Klicken auf den RecyclerView ausgelöst.Eltern-Klick-Ereignis wird nicht ausgelöst, wenn Recyclerview geklickt wurde
Hier ist, was die CardView wie folgt aussieht:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100"
android:minWidth="100dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/text1"
android:textColor="@color/abc_primary_text_material_light"
android:layout_weight="1"
android:layout_gravity="center_horizontal" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:listSelector="@color/highlighted_text_material_light"
android:layout_weight="98" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeSummary"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/text2"
android:textAlignment="viewEnd"
android:textColor="@color/abc_secondary_text_material_light"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="start"
android:singleLine="true"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/text3"
android:textColor="@color/abc_primary_text_material_light"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:gravity="end"
android:singleLine="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/text2" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
ich auf diesem RecyclerView keinen Klick Zuhörer brauchen und brauchen wirklich nur das Ereignis Click der übergeordneten Ansicht zu feuern, wenn der RecyclerView geklickt wird (Das gleiche gilt für das OnLongClick-Ereignis). Ich brauche auch den RecyclerView zum Scrollen. Ist der RecyclerView etwas wie das Klickereignis essen und es nicht an die Eltern weitergeben?
Der Nachteil dieses Ansatzes ist, dass der Selector der CardView nicht mehr verwendet wird, daher wird keine Rückmeldung von der CardView angezeigt. –
Es verbrauchen auch Klicks, die die RecyclerView-Elemente gehen sollten. –