5

I am using the stock SeekBar component to navigate through a set of ViewPagers and it's working quite fine. Only problem is that when the data changes, I have to dynamically change the max value of the SeekBar via setMax(int value). When I do that, the SeekBar does not get updated until I navigate to a new page. I have a hacky fix in place where I do this, to force a onProgressChanged:

seekBarVP.setProgress(focusedPage+1);
seekBarVP.setProgress(focusedPage-1);
seekBarVP.setProgress(focusedPage);

Is there a better way to do this?

oviroa
  • 1,079
  • 2
  • 12
  • 29

4 Answers4

12

Create updateThumb(); method in VerticalSeekbar

public void updateThumb(){
     onSizeChanged(getWidth(), getHeight(), 0, 0);
}

And then call update thumb method after setting progress.

seekBar.setProgress((int) progress);
seekBar.updateThumb();

its work for me in verticalseekbar calss

saravanan
  • 1,082
  • 1
  • 15
  • 30
  • worked for holoeverywhere seekbar with android 5.1.1 - however method `onProgressChanged` doesnt work anymore... – deadfish Jun 29 '15 at 15:56
  • Should invalidate() call fix it too? since it will redraw and remeasure width height? I tried with invalidate() call after setMax() but no luck. – Talha Jun 19 '17 at 06:56
7

The Question is some months old now but I'll answer anyway because searching for this problem brought me here.

Answer is there is actually a bug in Android. It seems to be fixed on my 3.2.1 tablet but the bug is present on my 2.3.6 phone. The bug is in the ProgressBar widget which is a parent of the SeekBar class. Your solution to setting the progress to a bogus value and back is so far the easies workaround I could find.

You will find more detailed information about this bug here: android progressBar does not update progress view/drawable

Community
  • 1
  • 1
Max Hille
  • 661
  • 7
  • 18
3

@saravanan Answer is correct. But should be done in this way.

Solved the issue by overriding setProgress in VerticalSeekbar class.

 @Override
    public synchronized void setProgress(int progress) 
    { 
        super.setProgress(progress); 
        onSizeChanged(getWidth(), getHeight(), 0, 0); 
    }
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
0

yes, I can confirm @saravanan's solution works great with VerticalSeekBar, but there is another way (better imho) to solve it, i.e. the answer of @TechnIx found here.

The basic solution is using this function in your VerticalSeekBar class:

public synchronized void setProgressAndThumb(int progress) {
    setProgress(getMax() - (getMax()- progress));
    onSizeChanged(getWidth(), getHeight() , 0, 0); }

Hope it helps!

Community
  • 1
  • 1
Andre
  • 489
  • 1
  • 6
  • 17