Ich habe einen CardView ein Image enthält. Jetzt habe ich einen onItemClickListener implementiert. Aber es funktioniert nur, wenn ich auf das Feld der CardView klicke, das nicht von der Bildansicht abgedeckt wird. Wenn ich auf die Bildansicht klicke, passiert nichts.RecyclerView: setOnClickListener nicht den Zugriff auf vollständige CardView
Wie kann ich erreichen, dass der onItemClick Methode des CardView auch genannt wird, wenn ich auf dem Image klicken?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_view_maschine"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="@dimen/card_margin"
android:elevation="6dp"
card_view:cardCornerRadius="@dimen/card_album_radius">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="@dimen/maschine_cover_height"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:scaleType="fitXY" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:paddingLeft="@dimen/maschine_title_padding"
android:paddingRight="@dimen/maschine_title_padding"
android:paddingTop="@dimen/maschine_title_padding"
android:textColor="@color/recyclerViewTitleColor"
android:textSize="@dimen/maschine_title" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:paddingBottom="@dimen/description_count_padding_bottom"
android:paddingLeft="@dimen/maschine_title_padding"
android:paddingRight="@dimen/maschine_title_padding"
android:textSize="@dimen/description_count" />
<ImageView
android:id="@+id/overflow"
android:layout_width="@dimen/ic_maschine_overflow_width"
android:layout_height="@dimen/ic_maschine_overflow_height"
android:layout_alignParentRight="true"
android:layout_below="@id/thumbnail"
android:layout_marginTop="@dimen/ic_maschine_overflow_margin_top"
android:scaleType="centerCrop"
android:src="@drawable/ic_dots" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
OnItemClick:
ItemClickSupport.addTo(recyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
showDetailFragment();
}
});
Ich habe das ItemClickSupport class verwendet.
führen in Ihrem Adapter cardview das Klick-Ereignis. –
Wenn Sie nicht möchten, dass imageview clickabke wird, dann setzen Sie das Attribut android: clickable auf false. Im Moment ist es so, dass es Touch-Events empfängt. –
@TalhaMir hat das Attribut auf false gesetzt. – jublikon