Recycleview Bug:java.lang.IndexOutOfBoundsException:Inconsistency detected.

Source: Internet
Author: User

Today when using Recyclerview, up and down two recyclerview, when the implementation of the drop-down refresh, error:

Java.lang.IndexOutOfBoundsException:Inconsistency detected.
Invalid View Holder Adapter positionviewholder{56798b2 position=2 id=-1, oldpos=2, plpos:-1 scrap [attachedscrap] TmpDeta Ched no parent}

See this method on the Internet to temporarily solve the problem

In fact, it is not a solution, just to catch this anomaly, do not let him collapse, the ultimate solution to the problem is to let Google to repair.

1. Create a class linearlayoutmanagerwrapper inherit Linearlayoutmanager, overriding the Onlayoutchildren method

[Java]View PlainCopy
  1. Public class Wrapcontentlinearlayoutmanager extends Linearlayoutmanager {
  2. Public Wrapcontentlinearlayoutmanager (context context) {
  3. super (context);
  4. }
  5. Public Wrapcontentlinearlayoutmanager (context context, int orientation, boolean reverselayout) {
  6. Super (context, orientation, reverselayout);
  7. }
  8. Public Wrapcontentlinearlayoutmanager (context context, AttributeSet attrs, int defstyleattr, int Defstyleres) {
  9. Super (context, Attrs, defstyleattr, defstyleres);
  10. }
  11. @Override
  12. public void Onlayoutchildren (Recyclerview.recycler recycler, recyclerview.state State) {
  13. try {
  14. Super.onlayoutchildren (recycler, state);
  15. } catch (Indexoutofboundsexception e) {
  16. E.printstacktrace ();
  17. }
  18. }
  19. }

2, set recyclerview layout Management for Wrapcontentlinearlayoutmanager object

[Java]View PlainCopy
    1. Mrecyclerview.setlayoutmanager (new Wrapcontentlinearlayoutmanager (This, linearlayoutmanager.vertical,  false));


Recycleview Bug:java.lang.IndexOutOfBoundsException:Inconsistency detected.

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.