ITeye博客

将耗时的操作放入handler中进行处理

AndLi · 2011-12-07 16:00 · Handler_Thread · 移动开发 · Markdown

// 初始化recList
	public void initRecList() {
		new Thread() {
			public void run() {
				try {
					sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				doInHandler();

			};
		}.start();

	}

	public void doInHandler() {

		if (!SDCard.getFileSavePath(pathString).toString().equals(null)) {
			recList.clear();
			handler.post(new Runnable() {
				public void run() {
					// 取得指定位置的文件,添加到recList中
					File home = new File(pathString);
					if (home.listFiles(new MusicFilter()).length > 0) {
						for (File file : home.listFiles(new MusicFilter())) {
							// 将录音文件的路径添加进recList
							recList.add(file.getPath().toString());
						}
					}
					recAdapter = new ListRecAdapter(getApplicationContext(),
							recList);
					recListView.setAdapter(recAdapter);
					// 关闭滚动条
					progressdialog.dismiss();
				}
			});
		} else {
			ShowMsg.showToast(getApplicationContext(), "请插入内存卡!");
		}

	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。