When adapter contents change (and you call notify*) RecyclerView requests a new layout. From that moment, until layout system decides to calculate a new layout (<16 ms), the layout position and adapter position may not match because layout has not reflected adapter changes yet.
The answer is very clear. The specific difference is that there will be a time difference between the positions of the adapter and layout (<16ms). If you change the data of the Adapter and then refresh the view, it will take a while for the layout to update the view. In this paragraph In time, the positions returned by these two methods will be different.
In addition, the answer also mentioned that the position in the Adapter cannot be obtained immediately after notifyDataSetChanged, and can only be obtained after the layout is completed. notifyDataSetChanged之后并不能马上获取Adapter中的position, 要等布局结束之后才能获取到.
而对于Layout的position, 在notifyItemInserted
As for Layout's position, after notifyItemInserted, Layout cannot get the new position immediately because the layout has not been updated yet (it takes
About this🎜
The answer is very clear. The specific difference is that there will be a time difference between the positions of the adapter and layout (<16ms). If you change the data of the Adapter and then refresh the view, it will take a while for the layout to update the view. In this paragraph In time, the positions returned by these two methods will be different.
In addition, the answer also mentioned that the position in the Adapter cannot be obtained immediately after
notifyDataSetChanged
, and can only be obtained after the layout is completed.notifyDataSetChanged
之后并不能马上获取Adapter中的position, 要等布局结束之后才能获取到.而对于Layout的position, 在
As for Layout's position, afternotifyItemInserted
notifyItemInserted
, Layout cannot get the new position immediately because the layout has not been updated yet (it takes About this🎜