Search code examples
androideclipsegraphprogress

Android fill progress bar with own data


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


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);