2

我想在名为myActivity. 我从活动中的一个方法启动它:

progressDialog = ProgressDialog.show(myActivity.this, "", "loading ...");

但什么也没有出现。为什么?

我也试过这条线:

progressDialog = ProgressDialog.show(myActivity.this, "", "loading ...",true);

结果相同。

4

2 回答 2

3

只是这个

//Declare progressDialog before so you can use .hide() later!
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.show();
于 2012-10-15T15:53:23.000 回答
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();
于 2018-06-26T04:57:58.970 回答