Search code examples
androidmathseekbar

Auto-Adjusting SeekBars Android


I have 6 SeekBars that range from 0-3000. I also have an algorithm that figures out what the difference would be if you would adjust one of the seekbars, so that at all times, all of the seekbars total will equal 3000. For example, if seekbar #1 = 1500 and seekbar #2 = 1500 and I change seekbar #1 to 1000, the difference would equal 500 and seekbar should jump to 2000 (1000 + 2000 = 3000). I can find the difference, but how to I update the other sliders?


Solution

  • SeekBar is a descendant of ProgressBar, therefore you should be able to call incrementProgressBy(int diff) on it. So, if you need to increment a slider by 500, you can call

    slider.incrementProgressBy(500);
    

    Of course you'll need to keep track of where it is now so that you don't increment beyond the maximum allowed limit.