Android Display and hide check boxes on all the rows of recyclerview
<p>i have a recyclerview and i need to display check boxes on clicking action bar menu like shown here <a href="https://i.stack.imgur.com/hsKyD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hsKyD.png" alt="show check boxes"></a></p>

<p>and like this to check all and hide all
<a href="https://i.stack.imgur.com/TORvd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TORvd.png" alt="hide/selectall"></a></p>

<p>How can i achieve something like this?? I tried to call a adapter method from my activity and set visiblity of checkbox to visible and then calling <code>notifyDataSetChanged()</code> but it displays checkbox in only one row.. here is my adapter code</p>

<pre><code>public class CartItemListAdapter extends RecyclerView.Adapter&lt;CartItemListAdapter.MyViewHolder&gt; {

    private List&lt;CartItemDetail&gt; cartItemDetailList;
    private Context context;
    private CheckBox checkbox;



    public CartItemListAdapter (List&lt;CartItemDetail&gt; cartItemDetailList){
        this.cartItemDetailList=cartItemDetailList;
    }


    public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView cartProductName, totalValue,leftValue;
        private ImageView cartProductImage, incrementButton,decrementButton;
        private EditText coinValue;




        public MyViewHolder(View view) {
            super(view);
            cartProductImage=(ImageView)view.findViewById(R.id.cart_product_image);
            incrementButton=(ImageView)view.findViewById(R.id.cartIncrementImg);
            decrementButton=(ImageView)view.findViewById(R.id.cartDecrementImg);
            coinValue=(EditText)view.findViewById(R.id.cartBetCoinValue);
            cartProductName=(TextView)view.findViewById(R.id.cart_product_name);
            totalValue=(TextView)view.findViewById(R.id.cart_ProductTotal_qty);
            leftValue=(TextView)view.findViewById(R.id.cart_ProductRemaining_qty);
            checkbox=(CheckBox)view.findViewById(R.id.cart_item_checkbox);
        }

        @Override
        public void onClick(View v) {

        }

    }



    @Override
    public CartItemListAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        context=parent.getContext();

        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.cart_item_row, parent, false);

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callProductEventDetails();
            }
        });


        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(CartItemListAdapter.MyViewHolder holder, int position) {
        CartItemDetail cartItemDetail=cartItemDetailList.get(position);
        holder.cartProductName.setText(cartItemDetail.getCartProductName());
        holder.leftValue.setText(Html.fromHtml("&lt;pre&gt;" + "Left:" + "&lt;/pre&gt;" + "&lt;font color=\"#EF4836\"&gt;" + cartItemDetail.getProductLeftQty() + "&lt;/font&gt;"));
        holder.totalValue.setText("Total:"+cartItemDetail.getProductTotalQty());
        holder.coinValue.setText(cartItemDetail.getAddedCoins());


        Glide.with(context)
                .load(cartItemDetail.getCartProductImageUrl())
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .fitCenter()
                .into(holder.cartProductImage);
}

    @Override
    public int getItemCount() {
        return cartItemDetailList.size();
    }

    private void callProductEventDetails(){
        Intent intent= new Intent(context, ProductEventDetailActivity.class);
        intent.putExtra("eventStatus","inProgress");
        context.startActivity(intent);
    }

    public void displayCheckBox(){
checkbox.setVisibility(View.VISIBLE);
        notifyDataSetChanged();
    }
}
</code></pre>

<p>xml for item row..</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_marginBottom="1dp"
    android:elevation="0dp"
    app:cardElevation="0dp"&gt;
&lt;LinearLayout
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"&gt;
    &lt;CheckBox
        android:visibility="gone"
        android:padding="-25dp"
        android:gravity="center"
        android:id="@+id/cart_item_checkbox"
        android:layout_gravity="center_vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleX="0.40"
        android:scaleY="0.40"
        android:button="@drawable/cart_checkbox_selector"/&gt;
    &lt;ImageView
        android:layout_marginLeft="10dp"
        android:id="@+id/cart_product_image"
        android:layout_gravity="center_vertical"
        android:layout_width="80dp"
        android:layout_height="80dp" /&gt;
    &lt;RelativeLayout
        android:padding="10dp"
        android:layout_marginLeft="10dp"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"&gt;
    &lt;TextView
        android:id="@+id/cart_product_name"
        android:layout_width="wrap_content"
        android:maxLines="2"
        android:ellipsize="end"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textColor="#1d1d1d"
        android:text="iPhone7 128G xxxxxxxxxxx xxx"/&gt;

        &lt;TextView
            android:id="@+id/cart_ProductTotal_qty"
            android:layout_marginTop="15dp"
            android:layout_below="@+id/cart_product_name"
            android:layout_alignParentLeft="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Total:750"/&gt;

        &lt;TextView
            android:layout_alignParentRight="true"
            android:layout_alignBaseline="@+id/cart_ProductTotal_qty"
            android:id="@+id/cart_ProductRemaining_qty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:text="Left:95"/&gt;
        &lt;LinearLayout
            android:layout_below="@+id/cart_ProductTotal_qty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:orientation="horizontal"
            android:background="@drawable/counter_stroke_border"&gt;
            &lt;ImageView
                android:id="@+id/cartDecrementImg"
                android:layout_margin="10dp"
                android:layout_gravity="center_vertical"
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:background="@drawable/minus_decrement"/&gt;
            &lt;View
                android:layout_width="0.6dp"
                android:layout_height="match_parent"
                android:background="#8d8d8d"&gt;&lt;/View&gt;
            &lt;EditText
                android:id="@+id/cartBetCoinValue"
                android:layout_width="70dp"
                android:layout_gravity="center_vertical"
                android:focusableInTouchMode="true"
                android:layout_height="wrap_content"
                android:textColor="#EF4836"
                android:ellipsize="start"
                android:gravity="center_horizontal"
                android:text="1"
                android:inputType="number"
                android:singleLine="true"
                android:background="@android:color/transparent"/&gt;
            &lt;View
                android:layout_width="0.6dp"
                android:layout_height="match_parent"
                android:background="#8d8d8d"&gt;&lt;/View&gt;
            &lt;ImageView
                android:id="@+id/cartIncrementImg"
                android:layout_margin="10dp"
                android:layout_gravity="center_vertical"
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:background="@drawable/plus_increment"/&gt;
        &lt;/LinearLayout&gt;
    &lt;/RelativeLayout&gt;

&lt;/LinearLayout&gt;
&lt;/android.support.v7.widget.CardView&gt;
</code></pre>