Skip to content Skip to sidebar Skip to footer

Multiselect Recyclerview

I want to achieve multiselect in recyclerview. I have almost got it but it behaves weirdly at times or when there are many items. I would like to have multiselect function where in

Solution 1:

Your Model should have

private boolean isSelected = false

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

in your onClick event,

Note: For Best practice setTag(position) with your position to your view that is getting clicked and use that tag value as a position.

int pos = (int) view.getTag(); 
list[pos].setSelected(!list[pos].isSelected());
                        notifyItemChanged(position);

I think this will resolve your problem regarding

I select the 1st record and scroll down then even the 8th record gets selected automatically. And if I select 2nd record then 9th one also gets selected.

Once you will use and operate using position with setTag() this issue of scrolling and position getting selected automatically will be eliminated


Solution 2:

Add one extra field in your model class

public boolean isSelected = false;

then after in bindViewHolder manage your check/uncheck view.

if the user clicks on your particular view you have to manage like below code.

list.get(position).setSelected(true);
notifyItemChanged(position);

Here, setSelected() is a method from your model class.


Post a Comment for "Multiselect Recyclerview"