Android ListView 局部刷新

	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			int what = msg.what;
			switch (what) {
			case CMD_UPDATE_TASK:
				int index = msg.arg1;
				DownloadTask task = mListItem.get(index);
				int firstVisible = mListView.getFirstVisiblePosition();
				int lastVisible = mListView.getLastVisiblePosition();
				if (index >= firstVisible && index <= lastVisible) {
					ViewHolder holder = (ViewHolder) (mListView
							.getChildAt(index - firstVisible).getTag());
					updateListViewItem(holder, task);
				}
				break;

			default:
				break;
			}
			// 避免全部刷新引起按钮响应很慢
			// mDownloadListAdapter.notifyDataSetChanged();
		};
	};

	private void updateListViewItem(ViewHolder holder, DownloadTask task) {
		// Log.d(TAG, "updateListViewItem "+task);
		holder.title.setText(task.name);
		holder.progress.setProgress(task.percent);
		switch (task.status) {
		case NOT_STARTED:
			holder.status.setText("开始");
			break;
		case RUNNING:
			holder.status.setText("下载中");
			break;
		case PAUSING:
			holder.status.setText("暂停");
			break;
		case WAITING:
			holder.status.setText("等待");
			break;
		case FINISHED:
			holder.status.setText("完成");
			break;
		default:
			break;
		}
	}

你可能感兴趣的:(多线程下载/断点下载,Android)