An exception occurred while sliding Recyclerview: java.lang.IndexOutOfBoundsException:Inconsistency detected. Invalid Item Position 6 (OFFSET:6). state:30

Source: Internet
Author: User

An obvious bug that exists in Recyclerview has not been fixed:

Java.lang. indexoutofboundsexception:inconsistency detected. Invalid Item Position ...

The way to reproduce this is: when using the Recyclerview Plus official dropdown refresh, if the bound List object is clear before updating the data, and then the user quickly on the RV, it will cause a crash, and the exception will not report to your code, the RV internal error. The first guess is, when you clear the list, then quickly slip, and the new data has not arrived, causing the RV to update loading the following Item when the data source is not found, resulting in crash.

But obviously, before updating the data clear list is quite common practice, you can not pray that the user at this time do not move to wait for new data loaded, so it is not reasonable at all.

    • There is also this problem on Stack Overflow, which cannot be resolved:
      How to change contents of Recyclerview while scrolling
    • Google Code Forum also has this issue, a bunch of threads, are described how to reproduce, not be able to solve:
      https://code.google.com/p/android/issues/detail?id=77846

Well, Google is sometimes really disappointing. Fortunately, I think of a way to solve the problem.

is in the refresh, that is clear at the same time, let Recyclerview temporarily not be able to slide, and then allow sliding. The code is when the Recyclerview is initialized and whether it is refreshed to intercept the gesture:

123456789101112 mRecyclerView.setOnTouchListener(        new View.OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                if (mIsRefreshing) {                    return true;                } else {                    return false;                }            }        });

Then go to change and restore Misrefreshing this Boolean. Imagine that if you do not let the user swipe very foolish, but have to do so, found that the real effect is perfect, very good! I think basically the use of Recyclerview will encounter this problem, so put it out, together to bypass the hole.

An exception occurred while sliding Recyclerview: java.lang.IndexOutOfBoundsException:Inconsistency detected. Invalid Item Position 6 (OFFSET:6). state:30

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.