How to select all items which listed in recyclerview?

前端 未结 4 1177
后悔当初
后悔当初 2021-01-13 03:39

I have list of items inside of recyclerview, and they are multiple selectable.

I want to have select button to select all, and if selected deselect all. I didn\'t se

4条回答
  •  执念已碎
    2021-01-13 04:30

    In my case,

    Step - 1 :- first globally initialize flag in activity class

    boolean flagSelectAll = false;

    Step - 2 :- Then set below code in Onclick of Button

    @OnClick(R.id.btnSelectAll)
    public void setBtnSelectAll(View view){
        for (int i=0;i

    Step - 3 :- Then create method selectAllItem in recyclerview's adpater class like below :

    public void selectAllItem(boolean isSelectedAll) {
            try {
                if (itemList != null) {
                    for (int index = 0; index < itemList.size(); index++) {
                        itemList.get(index).setSelected(isSelectedAll);
                    }
                }
                notifyDataSetChanged();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

提交回复
热议问题