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