【问题标题】:Android Studio - AlertDialog button listener, and view of ProgressBarAndroid Studio - AlertDialog 按钮监听器和 ProgressBar 视图
【发布时间】:2019-03-22 19:55:06
【问题描述】:

这是测试线程及其工作原理的代码! (看起来并没有真正连接)当警报对话框消失时,我想通过按下是按钮添加一个进度条,但它不起作用。我将可见性设置为之前消失,之后可见。似乎是什么问题?我选对了,其他地方也没有错。文字也没有改变.....请帮助:)

private void connectRequest() {    

    AlertDialog.Builder builder = new AlertDialog.Builder(ThreadActivity2.this);
    AlertDialog dialog = builder.setMessage("Do you request Remote Access?")
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    accessTv.setText("Requesting Remote Access ...");
                    accessPgb.setVisibility(View.VISIBLE);

                    try {
                        Thread.sleep(5700); 

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    accessTv.setText("Server Access Successful!");
                    accessPgb.setVisibility(View.GONE);

                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            }).create();

    dialog.show();


}

【问题讨论】:

    标签: multithreading android-studio android-progressbar


    【解决方案1】:

    尝试使用java.util.concurrent.TimeUnit:

    TimeUnit.SECONDS.sleep(1);
    

    睡一秒钟或

    TimeUnit.MINUTES.sleep(1);
    

    【讨论】:

    • 我不明白。我应该把它们放在哪里?这个问题是否与子线程无法访问主用户界面有关?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    • 2012-07-25
    • 2018-08-07
    相关资源
    最近更新 更多