-1

So I have a seekbar that I want to display or setProgress the value of that I get from SharedPreferences String, but since I can't use decimals, I am not 100% sure how to do this, can someone point me in the right direction?

String BarValue = "3.5";

Bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        float value = 0;

        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
            value = ((float)progress / 5);
        }

        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
            SharedPreferences.Editor e = sp.edit();
            e.putString("barValue", String.valueOf(value));
            e.apply();
        }
    });
Jayce
  • 781
  • 3
  • 16
  • 35

2 Answers2

2

Android Seekbar does not support float, so use integer in Seekbar and convert that to float as you want. I think that's the best way.

For example if you want to use single decimal place values like 11.6 you can set 116(11.6 * 10) to the Seekbar, and on retrieval divide that by 10. It will do the job.

Ajay Sivan
  • 2,807
  • 2
  • 32
  • 57
1

Android default SeekBar doesn't provide decimal value, if you want than you can use any custom SeekBar from following,

https://github.com/woxingxiao/BubbleSeekBar

https://github.com/syedowaisali/crystal-range-seekbar

https://github.com/vashisthg/StartPointSeekBar

Divy Soni
  • 824
  • 9
  • 22