smoothScrollToPosition后notifyDataSetChanged不是在Android平台 [英] smoothScrollToPosition after notifyDataSetChanged not working in android
问题描述
我有一个ListView的设置和工作确定一个自定义的适配器。点击一个按钮的东西在基础数据发生变化,所以notifyDataSetChanged需要刷新的ListView。精细。但我也想在ListView滚动到发生变化的地方就行了。为此,我的notifyDataSetChanged后立即拨打smoothScrollToPosition。这是行不通的。
I've got a custom Adapter for a ListView setup and working ok. On a button click something is changed in the underlying data, so a notifyDataSetChanged is required to refresh the ListView. Fine. But I also want the ListView to scroll to the line where the change occurred. For this I call smoothScrollToPosition immediately after the notifyDataSetChanged. And that is not working.
如果我不叫notifyDataSetChanged然后滚动的作品,所以通知块滚动。我可能有与事件的未来被处理的斗争。任何人都可以给我什么错误的指针?
If I do not call notifyDataSetChanged then the scroll works, so the notify blocks the scroll. I'm probably having a fight with events being processed in the future. Can anybody give me a pointer on what is going wrong?
推荐答案
使用后()
方法来等待列表以完成更新之后您调用 notifyDataSetChanged()
:
Use the post()
method to wait for the list to finish updating after you call notifyDataSetChanged()
:
adapter.notifyDataSetChanged();
list.post( new Runnable() {
@Override
public void run() {
//call smooth scroll
}
});
这篇关于smoothScrollToPosition后notifyDataSetChanged不是在Android平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!