I am trying to add a simple “View” view to a recycler view element, but for some reason I need to double-click the element and not once to complete the action. With one click, it seems that recycler View does not detect a click. On the next, however, it detects a click and performs a suitable action.
XML:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="wrap_content" > <RelativeLayout android:id="@+id/rlContainer" android:layout_width="match_parent" android:layout_height="wrap_content" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" android:background="@drawable/selector_inventory_recycler_item" android:padding="16dp"> <ImageView android:id="@+id/item_photo" android:layout_width="100dp" android:layout_height="100dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginRight="16dp" /> <TextView android:id="@+id/txtItemName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/item_photo" android:textSize="16sp" /> <TextView android:id="@+id/txtItemQuantity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtItemName" android:layout_toRightOf="@+id/item_photo" /> <TextView android:id="@+id/txtItemPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtItemQuantity" android:layout_toRightOf="@+id/item_photo" /> </RelativeLayout> </android.support.v7.widget.CardView>
CODE:
public class InventoryItemRecyclerAdapter extends RecyclerView.Adapter<InventoryItemRecyclerAdapter.InventoryItemViewHolder> { onItemClickListener mOnItemClickListener = null; public ArrayList<Product> mInventoryItemList; Context mContext; static String TAG = "InventoryItemRecyclerAdapter"; Random random = new Random();
I could not find the problem that causes this problem. May I get help on this. Thanks.
source share