【发布时间】:2017-01-13 09:19:58
【问题描述】:
我用变量名“dialog”创建了一个 ProgressDialog。
ProgressDialog dialog;
这是我的 ProgressDialog 代码:
//on upload button Click
if(selectedFilePath != null){
// dialog = ProgressDialog.show(MainActivity.this,"","Uploading File...",true);
dialog = new ProgressDialog(this);
dialog.setMessage("Uploading File");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setIndeterminate(true);
dialog.setMax(100);
dialog.show();
final int totalProgressTime = 100;
new Thread(new Runnable() {
@Override
public void run() {
int jumpTime = 0;
while(jumpTime < totalProgressTime) {
try {
Thread.sleep(2000);
jumpTime += 10;
dialog.setProgress(jumpTime);
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//creating new thread to handle Http Operations
uploadFile(selectedFilePath);
}
}).start();
}else{
Toast.makeText(MainActivity.this,"Please choose a File First",Toast.LENGTH_SHORT).show();
}
我的文件上传成功。但是我的进度条有问题,它总是 0% 并且没有上升。
看起来像这样:
【问题讨论】:
标签: android file-upload progressdialog android-progressbar