Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android filterable recyclerview with checkboxes

I am developing an app in which i have RecyclerView with checkboxes and a searchview.For searching from edit text i have added

enter image description here

search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

and in afterTextChanged() i am changing list and calling notifydatasetChanged()

but state of checkboxes are lost after search.is there any way to keep checkboxes state?

like image 383
Avinash Avatar asked Feb 14 '26 20:02

Avinash


1 Answers

Yes you can create ArrayList and save all selected items in that array. After notify list you can check that id`s , if its (contains)available in that array list then you will just checked that checkbox using setChecked(true);

For example:

// Creating and adding data in arraylist
ArrayList<String> selectedCat = new ArrayList<String>();
selectedCat.add('Your-selected-id');

//Checked array list item and placed in binder method
if(selectedCat.contains("Your-current-ids")){
  your-checkbox-object.setChecked(true);
}else{
  your-checkbox-object.setChecked(false);
}
like image 186
Manoj Srivastava Avatar answered Feb 17 '26 09:02

Manoj Srivastava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!