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开发者_JAVA百科. 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?
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
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
@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);
}
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!
精彩评论