我再写一个文件浏览器应用,但是再读取一些文件较多的文件夹得时候会需哟很长时间,我想再点击文件夹得时候加一个progressdialog,但是不知道如何判断文件读取已经结束,并关闭这个dialog,求高手指导。
解决方案 »
- android开发需要学习哪些东西
- Eclipse下安装ADT问题
- android开机铃声如何实现?
- android 源码中的Gallery问题???
- android drawText使用
- java源码 实现网页更新
- 求解 WARNING: Unknown device API version!
- android 4.0 USER_PRESENT监听不到??
- activity recreate问题
- android studio 在生成APK 的时候点击Generate Signed APK 没有任何反应
- android GridView刷新后 怎么让数据从第一项开始显示
- Android socket通信TCP协议发送数据顺序会乱。
如果是字节读取,一般返回-1是结束。 public static String readFileContent(String absPath) throws IOException{
File file = new File(absPath);
if (file.exists()) {
BufferedReader bw = new BufferedReader(new FileReader(file));
StringBuffer sb = new StringBuffer();
String line = null;
while ((line = bw.readLine()) != null) {
sb.append(line);
}
bw.close();
return sb.toString();
}
return null;
}
public static byte[] readInputStreamByte(InputStream ins) {
if (ins == null) {
return null;
}
BufferedInputStream bis = new BufferedInputStream(ins);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[128];
int n = -1;
while ((n = bis.read(buffer)) != -1) {
bos.write(buffer, 0, n);
}
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return bos.toByteArray();
}
protected void onListItemClick(ListView l,View v,int position,long id) {
File file = new File(paths.get(position));
currentlist.clear();
currentlist.addAll(paths);
//currentlist =paths;
if(file.isDirectory()) {
showDialog(DATAREADING); item_position_selected = getListView().getSelectedItemPosition();
item_position_first = getListView().getFirstVisiblePosition();
View cv = getListView().getChildAt(item_position_selected - item_position_first);
if (cv != null) {
fromtop_piexl = cv.getTop();
}
BrowserFile(paths.get(position));
if(!listFiles.isEmpty()) {
fileDirectory_position_selected.add(item_position_selected);
fileDirectory_position_piexl.add(fromtop_piexl);
pathLevel++;
}
}
现像是读取文件列表显示后才弹出对话框~
肯定是需要的,线程读取完之后就算读完了,你在线程代码执行的最后面,加一个handler 发消息就可以了
new Thread(){
public void run(){
int n = FileUtils.Process();//假设这样处理
if(n == 0){ //正常处理完
handler.sendEmptyMessage(0); //已经处理完了,发送消息。
}
}
}.start()
Dialog progressDialog = new ProgressDialog(this);
progressDialog.show();
new Thread(){
public void run(){
int n = FileUtils.Process();//假设这样处理
if(n == 0){ //正常处理完
handler.sendEmptyMessage(0); //已经处理完了,发送消息。处理完Dialog就关闭停止。
}
}
}.start()