Question

This question does not relate to the usual progress bar as in when the Android application is loading. I am trying to create a kind of progress bar as in showing for instance how much mb's you have left of the internet on your mobile phone.

I have information on how much the 100% amount is, as well as how much has been used. So when 50% has been used, I want the bar to fill up to 50% (or fill up 8 out of 16 for example, it doesn't have to be in %).

Example: http://cdn.css-tricks.com/wp-content/uploads/2013/08/reset-progress-bar.png

Was it helpful?

Solution

Just call ProgressBar.setMax and ProgressBar.setProgress. Example:

int maximum_number_of_megabytes = ...  // whatever the maximum is
int actual_number_of_megabytes = ...   // how much is used up

ProgressBar pb = (ProgressBar)findViewById(R.id.myprogressbar);
pb.setMax(maximum_number_of_megabytes);
pb.setProgress(actual_number_of_megabytes);

OTHER TIPS

Sounds like you want a determinate progress bar. Just apply the Widget.ProgressBar.Horizontal style:

<ProgressBar style="@android:style/Widget.ProgressBar.Horizontal" ... />

Increment progress using incrementProgressBy() or setProgress() by like so:

progressBar.setProgress(50);

to set it to 50% fullness (default max is 100)

Source: http://developer.android.com/reference/android/widget/ProgressBar.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top