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

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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With