我不能让progressdialog出现,我不知道为什么?
代码:
public class Activity001 extends Activity implements OnClickListener
{
public void onClick(View view)
{
ProgressDialog progressDialog = ProgressDialog.show(Activity001.this, "", "wait ", true, false);
// Sending some files to server .. takes time .. - (method that take 1-2 minutes )
progressDialog.dismiss();
}
}
有人能帮我一下吗?
最佳答案
试试这个。
在oncreate()中执行此操作
Handler handler;
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0) {
Pdialog.dismiss();
}
};
现在使用线程将文件上载到服务器。修改这段代码,
public class Activity001 extends Activity implements OnClickListener
{
public void onClick(View view)
{
ProgressDialog progressDialog = ProgressDialog.show(Activity001.this, "", "wait ", true, false);
Thread ProgressThread = new Thread() {
@Override
public void run() {
try {
// Sending some files to server .. take time .. - (method that take 1-2 minuts )
} catch(InterruptedException e) {
// do nothing
} finally {
handler.sendEmptyMessage(0);
}
}
};
ProgressThread.start();
}
}
编辑
进度对话框是一个轻量级对象。它不会优先于主线程中发生的其他任务。例如,当您在主线程中调用进程对话框的show()后接http进程或类似的程序时,它将不允许轻量级的prgoress对话框优先。所以很明显,它只会出现在http进程的末尾。