Note that there are some explanatory texts on larger screens.

plurals
  1. POany way to make a progress bar that when the value is 0, it's 100%?
    primarykey
    data
    text
    <p>I'm working on a debt tracking app, and have need for a progress bar that as the current debt goes down, the progress goes up. The only way I can think to do this would be to fudge the numbers around so that the progress bar MAX is set to 0, and then change the starting debt to be a negitive number, as follows</p> <pre><code>ProgressBar.setMax(0); Integer startingdebt = -1000; // 1000$ owed ProgressBar.setProgress(currentlyowed); //say, -500 </code></pre> <p>so you start with -1000, and add 500$ to it if you paid it. I don't know if this would work though, because I'm sure the progressbar control has a set minimum of 0 already, so you can't set max the same...is there a way to do this?</p> <p><strong>Edit:</strong> Thanks for the answers guys, but I found an easier way: to share with others, here's my final code block:</p> <pre><code> double startingamount = (this.c.getDouble(this.c.getColumnIndex(DbAdapter.KEY_STARTINGAMOUNT))); double currentamount = (this.c.getDouble(this.c.getColumnIndex(DbAdapter.KEY_CURRENTAMOUNT))); currentdebt.setText(formatter.format(currentamount)); double progresspaid = new Double(startingamount-currentamount); double progresspercentage = new Double((progresspaid / startingamount)*100); int progresspercent = (int)progresspercentage; progressbar.setText(Integer.toString(progresspercent)+"%"); progressbar.setMax(100); progressbar.setProgress(progresspercent); </code></pre> <p>the key was to get a variable that subtracts the current amount from the starting amount, and then divides that by the starting amount.</p> <pre><code>double progresspaid = new Double(startingamount-currentamount); double progresspercentage = new Double((progresspaid / startingamount)*100); </code></pre> <p>Thanks again though, I really appreciate people helping me learn Java and android development, I'm a VB.net developer so some of this is still foreign to me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload