Using SeekBar and setProgress doesn't change seekBar position

sowens picture sowens · Jun 26, 2013 · Viewed 18.6k times · Source

I am using a Seekbar in a fragment and need to move the Seekbar to different positions. However, setProgress(xxx) is not working.

How do you trigger this method programmatically for a Seekbar: public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)? Moving the Seekbar manually works fine.

Answer

AndroidGeek picture AndroidGeek · Feb 10, 2015

It's a Bug in ProgressBar!

The setProgress(...) seems to not trigger the update on the drawable if the same value is passed again. But it's not triggered during the setMax, too. So the update is missing.

To solve this, I'm just doing a bar.setProgress(0) before each update... this is only a workaround, but it works for me as expected:

bar.setProgress(0); // call these two methods before setting progress.
bar.setMax(20);
bar.setProgress(20);

Second Option.

mSeekBar.post(new Runnable() {
        @Override
        public void run() {
            mSeekBar.setProgress(percentOfFullVolume);
        }
    });

it may also work for someone.

Try to set max value first and then set the progress.