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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:29:15  来源:igfitidea点击:

Android notifyDataSetChanged

androidandroid-arrayadapter

提问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 Listdata structure that is feeding ArrayAdapter?

你如何更新List正在馈送的数据结构ArrayAdapter

Please see my answer here: notifyDataSetChanged example

请在此处查看我的答案:notifyDataSetChanged 示例

for issues regarding ArrayAdaptersand updating the Listthat holds data for notifyDataSetChangedto 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 :)

我有同样的问题,这是我的解决方案:)