2017-05-25 59 views
0

我有一个回收视图。我更新了它的适配器,并致电 notifydatasetchanged()如何检查我的RecycleView notifyDataSetChanged()何时完成?

。我想等到名单画完

+0

然后在new Handler() –

+0

中调用getLastVisiblePosition()请参考[This solution](https://stackoverflow.com/questions/29173588/how-do-i-check-when-my-listview-has-完成重绘),它应该解决您的问题 – TaoBit

+0

问题是我想插入项之间的recycleview项目,但在我插入之前,我做了一些计算与适配器的大小和所有,有时适配器还没有设置完成之前插入序列被执行。所以它只会导致代码中的严重滞后,并且只会变成一团糟。 – Peter

回答

0

试试这个。

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. 
        } 
       }); 
0

只补充一点:

recycler.post(() -> { 
    do something... 
}); 

做起来难。