How can I set the max value to 99,999
and min to 0.001
in seekbar ?
You can't. The SeekBar 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 SeekBar 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
SeekBar is taking only int value, not floating value if you want to set max value 99,999 and min value 0.001 then you can set max value 99,999*100 and min 0.001*100 then your ratio will display exactly.
And when you will display the percentage to user then get the value and divide by 100.
Seekbar progress is an int type so u have to change the progress value by float value by dividing Progress/1000.0
is as follows.
here is the java code:
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
edit1=(EditText)findViewById(R.id.edit1);
float value= (float) (progress / 1000.0);
edit1.setText((value)+"\n");
}
And layout u first try it as android:max="99"
The progress value will increment by 0.001 as you required upto the max value you can see those values in the edittext.
来源:https://stackoverflow.com/questions/15131724/android-seekbar-with-float-values