这是我更新listview的代码
Handler handler = new Handler(){
List> listItemx = new ArrayList>();
public void handleMessage(android.os.Message msg) {
if (msg.arg1 == 0X456) {
listItemx = (List>) msg.obj;
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), listItemx, R.layout.weather_simple_item,
new String[]{"city", "lowtemp", "hightemp", "week", "curTemp", "type", "fengli", "aqi"},
new int[]{R.id.city, R.id.lowtemp, R.id.hightemp, R.id.week, R.id.curTemp, R.id.type, R.id.fengli, R.id.aqi});
ListView list = (ListView) getView().findViewById(R.id.chat_weathers);
// 为ListView设置Adapter
list.setAdapter(simpleAdapter);
simpleAdapter.notifyDataSetChanged();
}
}
};
求大神啊
Adapter的初始化,和ListView.setAdapter 只需要执行一次,其他情况只要再listitemx集合里面操作就可以了。listItemx也写成全局的,每次只需要修改listItemx然后 调用Adapter的notifyDataChanged()方法就可以了。
handleMessage中,每次执行,都会初始为最初的数组,你不要这么干,每次网数据源中添加数据后,直接调用notifyDataSetChanged
结本贴,我自己鼓捣明白了