mercredi 23 mai 2018

CheckBox.setChecked() is getting executed but not shown on screen

I am using an onClickListener on a textview to setCheck() on a checkbox and saving the one value while clearing the last checked item in itemStateArray which is a SparseBooleanArray. The code is getting executed but the check box being checked is not shown.

textView.setOnClickListener(v -> {
            int adapterPosition = getAdapterPosition();
            if (!itemStateArray.get(adapterPosition, false)) {
                if (first) {
                    checkBox.setChecked(true);
                    first = false;
                    lastChecked = checkBox;
                } else {
                    if (checkBox.isChecked() && lastChecked != null) {
                        lastChecked.setChecked(false);
                        checkBox.setChecked(true);
                        lastChecked = checkBox;
                    }
                }
                itemStateArray.clear();
                itemStateArray.put(adapterPosition, true);

            } else {
                checkBox.setChecked(false);
                itemStateArray.clear();
                itemStateArray.put(adapterPosition, false);

            }
        });

I am setting the listener on the textview as I want to click on the larger textview as compared the smaller checkbox on the side of the screen.

Upon clicking the item and scrolling down and back up, the item is shown as checked. I am setting the checkbox as checked in the onBindViewHolder with the following code:

holder.bind(position);

The bind function to which I am passing the checked positions:

void bind(int position) {
            if (!itemStateArray.get(position, false)) {
                checkBox.setChecked(false);
            } else {
                checkBox.setChecked(true);
                lastChecked = checkBox;
            }
        } 

the checkbox being animated is not shown on the screen.




Aucun commentaire:

Enregistrer un commentaire