Recyclerview Item Status Disorder

Source: Internet
Author: User

In adapter:

1 Private New Arraylist<> ();

In the following method:

1  Public void Onbindviewholder (finalfinalint

Set the item's root layout tag to the current position:

// sets the view of the item background color, Settag itto ItemViewHolder.rl_item.setTag (position);

When judging, you can get the tag value of root layout, judge it, and set the item's current state.

1 if(Checkboxuseridlist.contains (ItemViewHolder.rl_item.getTag ())) {2ItemViewHolder.rl_item.setEnabled (false);3ItemViewHolder.check_box.setEnabled (true);4 ItemViewHolder.rl_item.setBackgroundResource (R.COLOR.GRAY_BG);5}Else {6ItemViewHolder.rl_item.setEnabled (true);7ItemViewHolder.check_box.setEnabled (false);8 ItemViewHolder.rl_item.setBackgroundResource (r.color.white);9}

This is due to the viewholder reuse, which causes the state of the disorder, so want to solve the state problem of this item:

1, Viewholder will not be reused, there is no checkbox confusion selected problems, but when you swipe the card to die:

1 viewholder.setisrecyclable (false

2. Set a flag bit in the bean that gets to it, but you need to modify the bean. Although it's just a matter of adding a field, it's not recommended.

3, that is, the code written above.

Reference: In fact, the same as the ListView reuse.

Recycleview checkbox multiplexing Chaotic Solution

Android ListView checkbox Status disorder

Recyclerview Item Status Disorder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.