0
我有一個回收視圖。我更新了它的適配器,並致電 notifydatasetchanged()
如何檢查我的RecycleView notifyDataSetChanged()何時完成?
。我想等到名單畫完
我有一個回收視圖。我更新了它的適配器,並致電 notifydatasetchanged()
如何檢查我的RecycleView notifyDataSetChanged()何時完成?
。我想等到名單畫完
試試這個。
recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//At this point the layout is complete and the
//dimensions of recyclerView and any child views are known.
}
});
只補充一點:
recycler.post(() -> {
do something...
});
做起來難。
然後在new Handler() –
中調用getLastVisiblePosition()請參考[This solution](https://stackoverflow.com/questions/29173588/how-do-i-check-when-my-listview-has-完成重繪),它應該解決您的問題 – TaoBit
問題是我想插入項之間的recycleview項目,但在我插入之前,我做了一些計算與適配器的大小和所有,有時適配器還沒有設置完成之前插入序列被執行。所以它只會導致代碼中的嚴重滯後,並且只會變成一團糟。 – Peter