Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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*/

}
like image 951
CQM Avatar asked Sep 16 '11 21:09

CQM


People also ask

What is progress bar in android?

Android ProgressBar is a graphical view indicator that shows some progress. Android progress bar displays a bar representing the completing of the task. Progress bar in android is useful since it gives the user an idea of time to finish its task.

What is indeterminate progress bar android?

Indeterminate Progress Bar is a user interface that shows the progress of an operation on the screen until the task completes. There are two modes in which you can show the progress of an operation on the screen. In this Android Indeterminate Progress Bar example, we will discuss in detail.

Why do we add progress bar on a layout?

In Android, ProgressBar is used to display the status of work being done like analyzing status of work or downloading a file etc. In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal.


2 Answers

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

like image 163
Johnny N Avatar answered Oct 07 '22 15:10

Johnny N


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.

like image 35
PravinCG Avatar answered Oct 07 '22 16:10

PravinCG