3

hey guys i am trying to make a set temperature app which has a seek bar and a textview. the readings of my temperature include values like 33.3 and 34.5. I know the code fore setting a seekbars progress is

seekbarTemperature.setProgress(int);

but i want to use float values like 33.3 or 39.8. if i convert a float into an int it rounds the value up to a whole number like 33 or 34. this will not position my seekbar properly because my seekbar will be positioned at 33 when my textview says 33.3. As i have also set the seekbar to increment or decrement by 0.1 it is vital that my seekbar is positioned accurately to the decimal. So can someone tell me how to set the seekbars progress position exactly to i.e. 33.4 not 33 or 34?

user2608169
  • 145
  • 3
  • 13

2 Answers2

9

you can not show ProgressBar progress with double value. but you can go for a simple mathematics.

set the ProgressBar maximum progress to 1000.
now when you want to show progress with value 33.3, update the ProgressBar with 333 like

 progressBar.setProgress(333);
Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
2

instead to have the seekbar going from 0 to 100 you could have it going from 0 to 1000 and 33.4 should be 334.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305