seekbar with multiple thumbs

582 Views Asked by At

I need help to create a seekbar with multiple thumbs.
Currently, I have a seekbar going from 1-100 KM. I am able to move the thumb in a fixed interval 1,2,3,4,5,6,7,8,9 etc.
I need help to move the thumb in flexible intervals etc 1,2,5,10,20,50,100.

Currently, I have the following:

    seekLocation.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            txtDistanceIncrease.setText(UnitConverter.getSeekbarDistanceByType(prefUtils, progress));

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
1

There are 1 best solutions below

2
Angel Koh On

you can try snapping your seekbar to the nearest interval when the user moves the progressbar. (e.g. 10 to 15 snaps to 10; 15 to 30 snaps to 20, etc...) kinda like the following.

int[] x_value = {1,2,5,10,20,50,100,..};
int maxValue = maxOf(x_value);
int minValue = minOf(x_value); 

seekbar.setMax(maxValue -minValue);

then at the seekbar onProgressChanged listener

onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){

   if(fromUser){
    int x = progress + minValue;
    //snap progress to the nearest x_value
    int nearestX = getNearestXValue(x, x_value);
    seekbar.setProgress(nearestX);

    updateChartline(nearestX);
   }

}