本文介绍了如何检查ListView完成重绘的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ListView
.我更新了其适配器,并调用notifydatasetchanged()
.我想等到列表完成绘制,然后在列表上调用getLastVisiblePosition()来检查最后一项.
I have a ListView
. I updated its adapter, and call notifydatasetchanged()
. I want to wait until the list finishes drawing and then call getLastVisiblePosition() on the list to check the last item.
在notifydatasetchanged()
之后立即调用getLastVisiblePosition()
不起作用,因为该列表尚未完成绘制.
Calling getLastVisiblePosition()
right after notifydatasetchanged()
doesn't work because the list hasnt finished drawing yet.
推荐答案
希望这会有所帮助:
- 在列表视图上设置addOnLayoutChangeListener
- 致电.notifyDataSetChanged();
- 完成后,这将触发OnLayoutChangeListener
- 删除收听者
-
在更新(
getLastVisiblePosition()
)上执行代码
- Setup a addOnLayoutChangeListener on the listview
- Call .notifyDataSetChanged();
- This will fire off the OnLayoutChangeListener once completed
- Remove the listener
Perform code on update (
getLastVisiblePosition()
)
mListView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
mListView.removeOnLayoutChangeListener(this);
Log.e(TAG, "updated");
}
});
mAdapter.notifyDataSetChanged();
这篇关于如何检查ListView完成重绘的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!