Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SeekBar and setProgress doesn't change seekBar position [duplicate]

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.

like image 581
sowens Avatar asked Jun 26 '13 06:06

sowens


Video Answer


1 Answers

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.

like image 128
Zar E Ahmer Avatar answered Oct 05 '22 23:10

Zar E Ahmer