android progressBar does not update progress view/drawable

Solution 1:

SOLUTION: It's a Bug in ProgressBar!

finally... I think I found the solution...

this does not work as one would expect:

bar.setMax(50);
bar.setProgress(20);
bar.setMax(20);
bar.setProgress(20);

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. Seems like a Bug in the android ProgressBar! This took me about 8 hours now.. lol :D

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.setMax(50);
bar.setProgress(20);
bar.setProgress(0); // <--
bar.setMax(20);
bar.setProgress(20);

Solution 2:

I was able to get this to work with View.post():

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // ...

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

As with SKTs answer it is unclear to me why this should work when this does not

mSeekBar.setProgress(percentOfFullVolume);

However, it seems to be true up to and including Android Lollipop.

Solution 3:

You can use a handler to update progressbar

Handler progressBarHandler = new Handler();

ProgressBar bar = (ProgressBar) findViewById(R.id.progressBar1);;

progressBarHandler .post(new Runnable() {

      public void run() {
          bar.setProgress(progress);
      }
});

Solution 4:

For me, calling setMax() before setProgress() worked for some reason.

Solution 5:

In my case, I create VerticalSeekBar, and solution of Stuck does not work. After hours, I have found a solution:

@Override
public synchronized void setProgress(int progress) {
    super.setProgress(progress);
    onSizeChanged(getWidth(), getHeight(), 0, 0);
}

Hope that help anyone.