Android Seekbar floating point values ​​from 0.0 to 2.0

how can i get values ​​from 0.0 to 2.0 using seekbar ? the values ​​should go in increments of 0.5 (0,0, 0,5, 1,0, 1,5, 2,0) can anyone help me?

+6
source share
3 answers

SeekBar extends ProgressBar.

ProgressBar has a method

 public void setMax(int max) 

Since it only accepts int, you will need to do some conversion from the int value to get the float that you are after it.

Something like this should do the trick:

 mSeekBar.setMax(4); //max = 4 so the possible values are 0,1,2,3,4 seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener(){ public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) { // TODO Auto-generated method stub Toast.makeText(seekBar.getContext(), "Value: "+getConvertedValue(progress), Toast.LENGTH_SHORT).show(); } public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); 

This part will be in your onCreate (), and you will need to use findViewById () or something to get the link to mSeekBar.

 public float getConvertedValue(int intVal){ float floatVal = 0.0; floatVal = .5f * intVal; return floatVal; } 

This part is another method that you can add to your activity, which will convert from int to float values ​​within the range that you need.

+13
source
  textView.setProgress(0); textView.incrementProgressBy(1); textView.setMax(4); public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { float progressD=(float) progress/2; textView.setText(String.valueOf(progressD)); 

// 0 to 2 steps 0.5

+1
source

You must implement your own search bar, make it jump between the desired values ​​and stick to them, you can find useful information here:

Creating a Custom Skinny ProgressBar / Seekbar

0
source

All Articles