我想在名为myActivity
的活动中使用进度对话框。
我从活动中的方法启动它:
progressDialog = ProgressDialog.show(myActivity.this, "", "loading ...");
但没有出现。为什么呢?
我也试过这一行:
progressDialog = ProgressDialog.show(myActivity.this, "", "loading ...",true);
具有相同的结果。
答案 0 :(得分:2)
就是这个
//Declare progressDialog before so you can use .hide() later!
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.show();
答案 1 :(得分:0)
请在您的代码中添加可运行线程
示例:https://abhiandroid.com/ui/progressdialog
或查看此示例代码
progressDialog.show(); // Display Progress Dialog
progressDialog.setCancelable(false);
new Thread(new Runnable() {
@Override
public void run() {
try {
while (progressDialog.getProgress() <= progressDialog.getMax()) {
Thread.sleep(200);
handle.sendMessage(handle.obtainMessage());
if (progressDialog.getProgress() == progressDialog.getMax()) {
progressDialog.dismiss();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}}).start();