The content of the adapter has changed but ListView did not receive a notification. Make sure the co

    在通知listview有时候,偶尔会冒出这样的错误:
The content of the adapter has changed but ListView did not receive a notification. 
  Make sure the content of your adapter is not modified from a background thread, but only from the UI thread 


    看了一下网上很多的分析,原因就是listview绑定的数据源改变了,没有及时的通知适配器去更新界面,我遇到的代码如下:
  
 // 删除成功之后,刷新界面
	 protected void refreshUI() {
	 maps.remove(position);
	
	 initFirstData();
	fireTableDataChange();
	}

	// 初始化加载控件
	private void initProgress() {
		progressDialog = DialogManager.showProgressDialog(this.getActivity(),
				"", "數據加載中...", DialogType.CloseHis);
	}

	// 首次加載頁面,初始化数据,更新界面
	private void inittipspriceData() {
		progressDialog.show();
		new Thread() {
			@Override
			public void run() {
				try {
					refreshUI();
				} finally {
					Runnable work = new Runnable() {

						@Override
						public void run() {
							progressDialog.dismiss();
						}
					};
					handler.post(work);
				}
			}
		}.start();
	}

	// 通知适配器更新
	public void fireTableDataChange</span>() {
		if (tipspriceAd == null) {
			return;
		}
		handler.post(new Runnable() {
			@Override
			public void run() {
				tipspriceAd.notifyDataSetChanged();
			}
		});
	}
        我新起了线程,对界面和数据进行更新,但有时候就会遇到上述的错误,后来我修改如下代码:
// 初始化加载控件
	private void initProgress() {
		progressDialog = DialogManager.showProgressDialog(this.getActivity(),
				"", "數據加載中...", DialogType.CloseHis);
	}

	// 首次加載頁面,初始化数据,更新界面
	private void inittipspriceData() {
		progressDialog.show();
		new Thread() {
			@Override
			public void run() {
				try {
					refreshUI();
				} finally {
					Runnable work = new Runnable() {

						@Override
						public void run() {
							progressDialog.dismiss();
						}
					};
					handler.post(work);
				}
			}
		}.start();
	}

	// 通知适配器更新
	public void refreshUI() {
		if (tipspriceAd == null) {
			return;
		}
		handler.post(new Runnable() {
			@Override
			public void run() {
				initFirstData();
				tipspriceAd.notifyDataSetChanged();
			}
		});
	}

     就是把获得数据源的代码同时放到了线程里面,及时通知更新,这样就没有问题,欢迎拍砖!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值