Changing step values in seekbar?

The easieset way I can think of, is simply defining:

SeekBar yourSeekBar = (SeekBar)findViewById(R.id.yourSeekBarId);
yourSeekbar.setMax(20);

Next, override those methods (the empty methods are also required, even if they are empty):

yourSeekbar.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) {
            if (fromUser) {
                if (progress >= 0 && progress <= sizeSeekBar.getMax()) {                        

                    String progressString = String.valueOf(progress * 10);
                    yourTextView.setText(progressString); // the TextView Reference
                    seekBar.setSecondaryProgress(progress);
                }
            }

        }
    });

The idea is to only define 20 values for the seekbar, but always multiply the value by 10 and display that value. If you do not really need 200 values, then there is no point in using 200 values.


Try below code

SeekBar seekBar = (SeekBar)layout.findViewById(R.id.seekbar);
seekBar.setProgress(0);
seekBar.incrementProgressBy(10);
seekBar.setMax(200);
TextView seekBarValue = (TextView)layout.findViewById(R.id.seekbarvalue);
seekBarValue.setText(tvRadius.getText().toString().trim());

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        progress = progress / 10;
        progress = progress * 10;
        seekBarValue.setText(String.valueOf(progress));
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
});

setProgress(int) is used to set starting value of the seek bar

setMax(int) is used to set maximum value of seek bar

If you want to set boundaries of the seekbar then you can check the progressbar value in the onProgressChanged method. If the progress is less than or greater than the boundary then you can set the progress to the boundary you defined.

Tags:

Android