ProgressDialog

时间:2017-05-26 21:55:11

标签: java android progressdialog

我有这段代码:

@Override
        public void onClick(View v) {
            progressDoalog = new ProgressDialog(Hack.this);
            progressDoalog.setMax(100);
            progressDoalog.setMessage("Its loading....");
            progressDoalog.setTitle("ProgressDialog bar example");
            progressDoalog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDoalog.show();
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        while (progressDoalog.getProgress() <= progressDoalog
                                .getMax()) {
                            Thread.sleep(200);
                            handle.sendMessage(handle.obtainMessage());
                            if (progressDoalog.getProgress() == progressDoalog
                                    .getMax()) {
                                progressDoalog.dismiss();
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }

        Handler handle = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                progressDoalog.incrementProgressBy(1);
            }
        };
    });
}

}

当ProgressDialog达到100%时,我可以在哪里添加代码来打开新活动?究竟是哪个地方?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

您无法从对话框启动活动,但您可以使用OnDismissListener从旧版本启动活动。

看看文件:

我没有注意到你可以检查你的处理程序的进度,检查它是否100%,关闭对话框并启动新的Activity,记住你必须在UI线程上执行此操作< / p>