Siddharth
Siddharth

Reputation: 9584

ProgressBar just wont show up and show any kind of progress

I have been trying for a while now, Have looked at a few SO posts, and got to this stage. I am sure I am very close to getting it working, but am missing something very basic.

Code Snippets of the activity below

public class SearchResultsMap extends MapActivity {
....
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.searchresultsmap);
    ...
        busy = (LinearLayout) findViewById(R.id.busy);
        busy.bringToFront();

        progressBar = (ProgressBar) findViewById(R.id.progressBar) ;
        progressBar.bringToFront() ;

        searchResponse = (HashMap<Integer, CustomJourneyUserInformation>) this.getIntent()
            .getSerializableExtra("searchResponse");
        new GetProviderAndUserDetails(this).execute(null); 
>>edit1  progressBar.setMax(searchResponse.size());
>>edit1  progressBar.setProgress(0) ;
    ...
    }

    //Inner Class, type AsyncTask
    public class GetProviderAndUserDetails extends AsyncTask<String, Integer, Object> {

    public GetProviderAndUserDetails(Activity mapActivity) {
        this.mapActivity = mapActivity;
    }

    protected void onPreExecute() {
        busy.setVisibility(View.VISIBLE);
        setProgressBarVisibility(true) ;
        setProgressBarIndeterminate(true) ;
        setProgressBarIndeterminateVisibility(true) ;
    }
    @Override
    protected void onProgressUpdate(Integer... progress) {
        if (searchActivity != null) {
            searchActivity.setProgress(progress[0]);
>>edit1     progressBar.setProgress(progress[0]) ;
        }
    }
    @Override
    protected Object doInBackground(String... args) {
         ...
         //for loop, i
         publishProgress(i) ;
         //end for loop
         ...
    }
    protected void onPostExecute(Object result) {
        super.onPostExecute(result);
        busy.setVisibility(View.GONE);
        setProgressBarVisibility(false) ;
        setProgressBarIndeterminate(false) ;
        setProgressBarIndeterminateVisibility(false) ;
        ...
    }
}

Layout XML File

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/busy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:visibility="visible" >

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:indeterminateOnly="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp" />
    </LinearLayout>

    .....

    <com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/searchMap"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/tip"
        android:layout_alignParentTop="true"
        android:apiKey="mykey"
        android:clickable="true" />

    ....

</RelativeLayout>

Device Results : Unable to upload to stackoverflow. Some SO issue.

searchresults image

Upvotes: 1

Views: 416

Answers (2)

Siddharth
Siddharth

Reputation: 9584

Setting the style to progressBarStyleHorizontal in the xml worked finally. Seems like progressBarStyleLarge cant show progress.

Also the indeterminate thing helped.

Upvotes: 0

j__m
j__m

Reputation: 9645

You're calling setProgressBarIndeterminate() and related functions, which act on your activity's title, not on the progress bar in your layout.

Use progressBar.setIndeterminate() and friends instead.

EDIT: And if you want a progress bar instead of the indeterminate progress indicator, use setIndeterminate(false).

Upvotes: 1

Related Questions