问题描述
我是从我的后台方法来更新我的列表视图:
I'm updating my listview from my background method:
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
BaseAdapter adapter = new SimpleAdapter(
AllProductsActivity.this, productsList,
R.layout.list_item, new String[] { TAG_PID,
TAG_NAME},
new int[] { R.id.pid, R.id.name });
// updating listview
if(getListView().getAdapter() == null){ //Adapter not set yet.
setListAdapter(adapter);
Log.v("ha", "bla");
}
else
{ //Already has an adapter
adapter.notifyDataSetChanged();
}
}
});
这code被执行:结果
-on第一次加载结果
-on滚动加载更多的内容,在这里我称之为 adapter.notifyDataSetChanged()
,但没有成功。
This code is executed:
-on first load
-on scroll to load more content, where I call adapter.notifyDataSetChanged()
, but without success.
我如何更新我的code,所以我可以用notifydatasetchanged和新数据添加到当前的数据。
How can I update my code so I can use notifydatasetchanged and add the new data to the current data.
我的整个code:任何帮助AP preciated。
My whole code: http://pastebin.com/cWmday3i Any Help is appreciated.
推荐答案
你写你的code,你应该始终调用方式 setListAdapter
,因为每次可运行时间内部执行runOnUiThread,创建一个新的适配器,可能与新的数据集。唯一的区别 notifyDataSetChanged
和 NotifyDataSetChanged
是第二个不属于Android的API
the way you wrote your code you should always call setListAdapter
, because every time the runnable inside runOnUiThread is executed, you create a new Adapter, probably with a new data set. The only difference between notifyDataSetChanged
and NotifyDataSetChanged
is that the second one does not belong to the Android's API
这篇关于notifyDataSetChanged()不更新列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!