1

I need two SeekBars for setting a minimum and maximum, and the thumb on each SeekBar cannot move past the other. Is there a way to disallow moving the SeekBar past a specific point?

Shawn Lauzon
  • 6,234
  • 4
  • 35
  • 46

1 Answers1

0

Found the solution myself: in SeekBar.OnSeekBarChangeListener.onProgressChanged() method, just set the progress to a correct value, which in this case is the same as the other SeekBar

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
    if (!isLegalMove(seekBar)) {
        seekBar.setProgress(mOtherSeekBar.getProgress());
    } 
}

private boolean isLegalMove(SeekBar thisSeekBar) {
    if (mOtherSeekBar == null) {
        return true;
    }
    return mIsMax && mOtherSeekBar.getProgress() <= thisSeekBar.getProgress() ||
        !mIsMax && mOtherSeekBar.getProgress() >= thisSeekBar.getProgress();
}
Sree
  • 3,136
  • 2
  • 31
  • 39
Shawn Lauzon
  • 6,234
  • 4
  • 35
  • 46