Android Seekbar Float Values From 0.0 To 2.0
how can I get the values from 0.0 to 2.0 with a seekbar? values should go in steps of 0.5 ( 0.0 , 0.5 , 1.0, 1.5, 2.0) can someone help me?
Solution 1:
SeekBar extends ProgressBar.
ProgressBar has a method
publicvoidsetMax(int max)
Since it only accepts int you'll have to do some conversion from an int value to get the float that you are after.
Something like this should do the trick:
mSeekBar.setMax(4);
//max = 4 so the possible values are 0,1,2,3,4
seekbar.setOnSeekBarChangeListener( newOnSeekBarChangeListener(){
publicvoidonProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
{
// TODO Auto-generated method stubToast.makeText(seekBar.getContext(), "Value: "+getConvertedValue(progress), Toast.LENGTH_SHORT).show();
}
publicvoidonStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
publicvoidonStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
This part will be in your onCreate() and you'll have to use findViewById() or something to get a reference to mSeekBar.
publicfloatgetConvertedValue(int intVal){
float floatVal = 0.0;
floatVal = .5f * intVal;
return floatVal;
}
This part is another method that you can add to your Activity that will convert from int to float values within the range you need.
Solution 2:
textView.setProgress(0);
textView.incrementProgressBy(1);
textView.setMax(4);
publicvoidonProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
float progressD=(float) progress/2;
textView.setText(String.valueOf(progressD));
// from 0 to 2 step 0.5
Solution 3:
You should implement your own custom seek bar, make it jump between the desired values and stick to them, you could find useful info here:
Post a Comment for "Android Seekbar Float Values From 0.0 To 2.0"