notifyDataSetChanged()不能更新listview,不知道怎么回事 notifyDataSetChanged是在ui线程中更新的?代码贴出来看看。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.foundation); getapp();//主线程调用了一次 }public void onRefresh() { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { SystemClock.sleep(1000); getapp();//此处线程调用一次 mListView.setVisibility(View.VISIBLE); return null; }public void getapp() { List<AppInfo> appList = new ArrayList<AppInfo>(); for(int i = 0; i < string.length; i++) { AppInfo tmpInfo = new AppInfo(); //此处省略赋值语句 appList.add(tmpInfo); } adapter = new ListViewAdapter(this, appList);// if (test==0) { mListView.setAdapter(adapter); test=1; } else { appList.clear(); appList.addAll(appList); adapter.notifyDataSetChanged(); } } AsyncTask用法不對,不要在子線程(doInBackground)更新ui 你debug看下有没有执行 else { appList.clear(); appList.addAll(appList); adapter.notifyDataSetChanged(); } 是不是应该放在onPostExecute运行还有就是debug调试运行到了else哪里,都很正常 appList.clear(); appList.addAll(appList); adapter.notifyDataSetChanged();中clear完后,你得先重新再获取一遍applist,List<AppInfo> appList = new ArrayList<AppInfo>(); for(int i = 0; i < string.length; i++) { AppInfo tmpInfo = new AppInfo(); //此处省略赋值语句 appList.add(tmpInfo);然后再刷新 clear只是清除以前的数据,和现在的数据无关 送分的帖子。简单易答 怎么让下载Thread暂停 求完整的安卓sdk 用SurfaceView和MediaPlayer播放视频尺寸问题 android录音开发,怎么设置频率范围? HTC的G8刷机驱动的问题,求解!!!!!!!!!!!!!!!!!!!!!! 如何android中利用opencore开发cmmb播放器? 安智网和首都信息发展股份有限公司,哪家更好? 有人做过护目镜吗?怎么突破系统限制的最低屏幕亮度啊 res.locale.getCountry获取国家,这个在哪配置的? 2013年度【博客之星评选活动】正在进行中,希望大家支持下,十分感谢! ant打包不同包名的apk
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.foundation);
getapp();//主线程调用了一次
}public void onRefresh() {
new AsyncTask<Void, Void, Void>() { @Override
protected Void doInBackground(Void... params) {
SystemClock.sleep(1000);
getapp();//此处线程调用一次 mListView.setVisibility(View.VISIBLE);
return null;
}public void getapp() {
List<AppInfo> appList = new ArrayList<AppInfo>(); for(int i = 0; i < string.length; i++) {
AppInfo tmpInfo = new AppInfo();
//此处省略赋值语句
appList.add(tmpInfo);
}
adapter = new ListViewAdapter(this, appList);//
if (test==0)
{
mListView.setAdapter(adapter);
test=1;
}
else
{
appList.clear();
appList.addAll(appList);
adapter.notifyDataSetChanged();
} }
{
appList.clear();
appList.addAll(appList);
adapter.notifyDataSetChanged();
}
还有就是debug调试运行到了else哪里,都很正常
appList.addAll(appList);
adapter.notifyDataSetChanged();
中clear完后,你得先重新再获取一遍applist,
List<AppInfo> appList = new ArrayList<AppInfo>(); for(int i = 0; i < string.length; i++) {
AppInfo tmpInfo = new AppInfo();
//此处省略赋值语句
appList.add(tmpInfo);
然后再刷新