Android - ProgressBar setVisibility to GONE not working

后端 未结 5 2352
无人及你
无人及你 2021-02-20 08:59

I\'ve been adding a ProgressBar to the fragments in my app. I\'ve set it up to the two main fragments (used as tabs) as follows:

ProgressBar in

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-20 09:52

    I had a same issue (progressBar.setVisibility() was not working).

    As @Illegal Argument said,

    // in Activity
    ProgressBar mProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
    mProgressBar.setVisibility(View.GONE); 
    

    should be working, if that code runs on uiThread(mainThread).

    My problem was that I was trying to run the code not on uiThread. So I solved the issue by changing code from

    mProgressBar.setVisibility(View.GONE);
    

    to

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mProgressBar.setVisibility(View.GONE);
        }
    });
    

提交回复
热议问题