How to set seekbar min and max value

Solution 1:

You cannot set the min value of a SeekBar (always 0) and you cannot set the step value of a SeekBar (always 1).

To set the value from 60 to 180 with a step of 1:

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);

        }
    }
);

I put another example within the code so that you understand the math.

Solution 2:

You can set max value for your seekbar by using this code:

    sb1.setMax(100);

This will set the max value for your seekbar.

But you cannot set the minimum value but yes you can do some arithmetic to adjust value. Use arithmetic to adjust your application-required value.

For example, suppose you have data values from -50 to 100 you want to display on the SeekBar. Set the SeekBar's maximum to be 150 (100-(-50)), then subtract 50 from the raw value to get the number you should use when setting the bar position.

You can get more info via this link.