vendredi 9 juillet 2021

How to prevent from CheckedChangeListener when CheckBox is checked programmatically

I've got many CheckBoxs in a RecyclerView and by scrolling, their views recycle. Meanwhile, their checked status change programmatically and CheckedChangeListener is called.

holder.checkBox.setChecked(preferences.getBoolean(itemList.get(position), false));

holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editor.putBoolean(itemList.get(position), isChecked);
            editor.commit();
        }
    });

How can I prevent calling this method when the checked status is changed programmatically?




Aucun commentaire:

Enregistrer un commentaire