Skip to content

Instantly share code, notes, and snippets.

@netsmertia
Last active November 5, 2016 03:15
Show Gist options
  • Save netsmertia/d32d56931290ae07580df2c883fbb098 to your computer and use it in GitHub Desktop.
Save netsmertia/d32d56931290ae07580df2c883fbb098 to your computer and use it in GitHub Desktop.
Seekbar setMax
//You cannot set the min value of a SeekBar (always 0) and you cannot set the step value of a SeekBar (always 1).
//If you want to set the value from 60 to 180 with a step of 1 this is the way to do it
//From http://stackoverflow.com/questions/20762001/how-to-set-seekbar-min-and-max-value
int step = 1;
int max = 180;
int min = 60;
// Ex :
// If you want values from 3 to 5 with a step of 0.1 (3, 3.1, 3.2, ..., 5)
// this means that you have 21 possible values in the seekbar.
// So the range of the seek bar will be [0 ; (5-3)/0.1 = 20].
seekbar.setMax( (max - min) / step );
seekbar.setOnSeekBarChangeListener(
new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
// Ex :
// And finally when you want to retrieve the value in the range you
// wanted in the first place -> [3-5]
//
// if progress = 13 -> value = 3 + (13 * 0.1) = 4.3
double value = min + (progress * step);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment