读书人

将耗时的操作放入handler中开展处理

发布时间: 2012-08-15 16:57:17 作者: rapoo

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

// 初始化recListpublic 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())) {// 将录音文件的路径添加进recListrecList.add(file.getPath().toString());}}recAdapter = new ListRecAdapter(getApplicationContext(),recList);recListView.setAdapter(recAdapter);// 关闭滚动条progressdialog.dismiss();}});} else {ShowMsg.showToast(getApplicationContext(), "请插入内存卡!");}}

?

读书人网 >移动开发

热点推荐