问题
PROGRESS BAR:
ProgressBar pb = (ProgressBar) findViewById(R.id.progressbar);
pb.setProgress(0);
int k = (int)max;
pb.setMax(k);
int j = (int)(cost);
pb.setProgress(j);
this code for a progress bar that only take an int value i want to change the code to take a double value
回答1:
You can't. The ProgressBar
widget only accepts ints
for its max and current progress. You can't control the minimum, as it is always 0
.
You could multiply your required maximum and current progress values by a power of 10, such that the decimal goes away. The ProgressBar
will still show the same amount of progress as it would with a decimal value, as the progress is a ratio of currentValue/maxValue
. As you'll be multiplying both by the same number, the ratios are equal. For example:
0.1/10 = 0.01
However, if you multiple both 0.1 and 10 by 10 to get rid of the decimal, you get:
1/100 = 0.01 //Same result
回答2:
It accept only integer value. There is no method
for that to pass the double value.
public synchronized void setProgress (int progress)
Look android developer docs.
Parameters
progress the new progress, between 0 and getMax()
来源:https://stackoverflow.com/questions/15418571/change-progress-bar-into-double