Search code examples
androidseekbar

Android seekbar with float values


How can I set the max value to 99,999 and min to 0.001 in seekbar ?


Solution

  • 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