Android notifyDataSetChanged
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2345875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android notifyDataSetChanged
提问by xger86x
I have a list which is filled with a custom ArrayAdapter
.
我有一个列表,其中包含自定义ArrayAdapter
.
I want to update a progress bar every second, so I am trying to use notifyDataSetChanged()
in order to repaint the list but it doesn't seem to work.
我想每秒更新一个进度条,所以我试图使用notifyDataSetChanged()
它来重新绘制列表,但它似乎不起作用。
采纳答案by jnosek
How are you updating the List
data structure that is feeding ArrayAdapter
?
你如何更新List
正在馈送的数据结构ArrayAdapter
?
Please see my answer here: notifyDataSetChanged example
请在此处查看我的答案:notifyDataSetChanged 示例
for issues regarding ArrayAdapters
and updating the List
that holds data for notifyDataSetChanged
to work.
有关ArrayAdapters
和更新List
保存数据的notifyDataSetChanged
问题。
回答by snctln
If you are not calling this from the main thread try having the main thread call this function. That is usually the problem when notifyDataSetChanged isn't updating the actual screen contents.
如果您不是从主线程调用此函数,请尝试让主线程调用此函数。当notifyDataSetChanged 未更新实际屏幕内容时,这通常是问题所在。
回答by ndsvw
I probably have the answer. Try this:
我大概有答案了。尝试这个:
((BaseAdapter) arrayAdapter).notifyDataSetChanged();
I had the same problem and this was the solution for mine :)
我有同样的问题,这是我的解决方案:)