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
- Public class Wrapcontentlinearlayoutmanager extends Linearlayoutmanager {
- Public Wrapcontentlinearlayoutmanager (context context) {
- super (context);
- }
- Public Wrapcontentlinearlayoutmanager (context context, int orientation, boolean reverselayout) {
- Super (context, orientation, reverselayout);
- }
- Public Wrapcontentlinearlayoutmanager (context context, AttributeSet attrs, int defstyleattr, int Defstyleres) {
- Super (context, Attrs, defstyleattr, defstyleres);
- }
- @Override
- public void Onlayoutchildren (Recyclerview.recycler recycler, recyclerview.state State) {
- try {
- Super.onlayoutchildren (recycler, state);
- } catch (Indexoutofboundsexception e) {
- E.printstacktrace ();
- }
- }
- }
2, set recyclerview layout Management for Wrapcontentlinearlayoutmanager object
[Java]View PlainCopy
- Mrecyclerview.setlayoutmanager (new Wrapcontentlinearlayoutmanager (This, linearlayoutmanager.vertical, false));
Recycleview Bug:java.lang.IndexOutOfBoundsException:Inconsistency detected.