Search code examples
androidpositionandroid-seekbar

setting points on seekbar - ANDROID


I want to be able to set points or steps on the seekbar. I have about 4-5 values that will change according to the position of the seek bar. The way I doing this now is by saying if seekbar position is below 25 then first value, if seekbar position is below 50 second value etc. It would be better if I can just have 4 position on the seekbar instead of 1->100. I have provided a picture below if what I mean.

enter image description here

Code: Slider is the seekbar, slidertext is a textview

slider.setOnSeekBarChangeListener(
                new SeekBar.OnSeekBarChangeListener() {
                    int sliderValue;
                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        sliderValue= progress;
                        sliderText.setText("Slider Position: " + sliderValue  + "/" + slider.getMax());
                        if(sliderValue <= 25){
                            playerInput.setText("Player1");
                        }
                        else if(sliderValue <= 50){
                            playerInput.setText("Player2");
                        }
                        else if(sliderValue <= 75){
                            playerInput.setText("Player3");
                        }
                        else if(sliderValue <= slider.getMax()){
                            playerInput.setText("Player4");
                        }
                    }

Solution

  • You can change the number of positions to 4 by calling

        slider.setMax(4);