Get list of checked checkboxes from recyclerview android

前端 未结 7 1505
慢半拍i
慢半拍i 2020-12-24 02:40

I have populated the recyclerView with image, title and checkbox. I have two problems.

  1. How to make the checkbox selected when the imageview or the whole rec

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 03:10

    This work for me and will work for you as well Just Create Static List, I created it on MainActivity.java

    public static List myItems = new ArrayList<>();
    

    Create setOnCheckedChangeListener in YouAdapter.class

    holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    myItems.add(Model.getYouItem());
                }
                else{
                    myItems.remove(Model.getYouItem());
                }
            }
        });
    

    Now you can use your myItems list to perform operations.

提交回复
热议问题