CQM
CQM

Reputation: 44278

Android progressBar not showing

I have a progressbar that is supposed to run in an AsyncTask , but it is not appearing, although the task runs

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/splashportrait">
<ProgressBar android:layout_alignParentBottom="true" android:indeterminate="true"
    android:layout_centerHorizontal="true" android:paddingBottom="450dip"
    android:layout_width="200dip" android:layout_height="200dip"
    android:id="@+id/progressBar1"></ProgressBar>
</RelativeLayout>

CODE:

ProgressBar diagProgress;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashscreen);

    diagProgress = (ProgressBar)findViewById(R.id.progressBar1);
    DiagnosticsTask diag = new DiagnosticsTask();
    diag.execute();

  /**rest of class ommitted here**/
}

private class DiagnosticsTask extends AsyncTask<String, String, Boolean> {

    //Show spinner
    protected void onPreExecute() {
        //dialog.setMessage("Loading corresponding destinations...");
        //dialog.show();
        diagProgress.setVisibility(View.VISIBLE);
        diagProgress.showContextMenu();
        Log.e("AsyncStatus", "spinner shown");
    }
 /*other parts of the thread ommitted here*/

}

Upvotes: 17

Views: 51204

Answers (5)

STCoder54
STCoder54

Reputation: 1

I had this issue. I solved it by going into themes.xml and undoing the changes I made to the primary brand colors.

The progress bar appeared when I changed it back to these colors:

<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>

Upvotes: 0

Radhey
Radhey

Reputation: 1

I had that issue when I make visibility gone and visible instant of gone make invisible in my case working invisible and visible

private fun hideShowProgressBar(isShowProgress:Boolean){
    if(isShowProgress){
            progressBar.visibility = View.VISIBLE
            tvSetProgress.visibility = View.VISIBLE
    }else{
        progressBar.visibility = View.INVISIBLE
        tvSetProgress.visibility = View.INVISIBLE
    }
}

Upvotes: 0

PravinCG
PravinCG

Reputation: 7708

Try this replace your ProgressBar with the one below.

<ProgressBar
    android:id="@+id/progressBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:indeterminate="true"
    />

Let me know if it works, I would explain the rationale.

Rationale: Now I am putting your code below for ProgressBar

<ProgressBar
    android:id="@+id/progressBar1"
    android:layout_width="200dip"
    android:layout_height="200dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:indeterminate="true"
    android:paddingBottom="450dip"
    />

RelativeLayout allows you Z-ordering. So since you needed ProgressBar on top you need not do the kind of manipulations you are doing.

android:layout_alignParentBottom="true"  

This sets the Progress Bar at the botton of the layout:

android:paddingBottom="450dip" android:layout_width="200dip" android:layout_height="200dip"

All the three values here are absolute which is a strict no-no as far as Android is concerned. Most Likely your paddingBottom was pushing your ProgressBar out of View. As your padding is greater than the actual width/height of the control

As a thumb rule always use relative values for it to work on all the devices and form factors.

Let me know if this makes sense.

Upvotes: 25

Johnny N
Johnny N

Reputation: 559

I had that issue when I forgot to turn on animations after testing xD

Upvotes: 43

dmon
dmon

Reputation: 30168

Did you forget to execute your task?

  ...
  diagProgress = (ProgressBar)findViewById(R.id.progressBar1);
  new DiagnosticsTask().execute();


  ....

Upvotes: 0

Related Questions