进度条不在线程之前显示

时间:2018-11-01 14:40:36

标签: android

我正在尝试在线程之前显示进度条,但未显示。我的代码如下所示:

        runOnUiThread(new Runnable() {
            @Override
            public void run() {

                progressBar.setVisibility(View.VISIBLE);
            }
        });



        Thread thread = new Thread(new Runnable() {
            public void run() {

        //doSomeStuff();

            }
        });
        thread.start();
        try {
            thread.join();

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

您有什么建议吗?

1 个答案:

答案 0 :(得分:0)

尝试一下。如果要设置进度,则需要在进度栏中设置当前进度

   progressBar = (ProgressBar) findViewById(R.id.progressBar);
    progressStatus = 0;
   // Start long running operation in a background thread
            runOnUiThread(new Runnable() {
                public void run() {
                    progressBar.setVisibility(View.VISIBLE);
                    while (progressStatus < 100) {
                        progressStatus += 1;
                        // Update the progress bar and display the
                        //current value in the text view
                        handler.post(new Runnable() {
                            public void run() {
                                progressBar.setProgress(progressStatus);
                            }
                        });