Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SeekBar doesn't refresh after dynamically setting max value with setMax

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?

like image 700
oviroa Avatar asked Sep 15 '11 22:09

oviroa


People also ask

How do you set the minimum and maximum value of SeekBar in android programmatically?

setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub //int inVal = Integer. parseInt(String. valueOf(seekBar. getProgress())); //inVal =+ 70; //Toast.

How do I change my SeekBar value?

In Order to the seekBar to Change while you are in the Activity you need to Call the method setProgress(), and pass it a boolean animate value.

How do I SeekBar progress?

In Android, SeekBar is an extension of ProgressBar that adds a draggable thumb, a user can touch the thumb and drag left or right to set the value for current progress.

How do I start SeekBar on Android?

Step1: Create a new project. After that, you will have java and XML file. Step2: Open your xml file and add a SeekBar and TextView for message as shown below, max attribute in SeekBar define the maximum it can take. Assign ID to SeekBar And TextView.


1 Answers

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

like image 197
saravanan Avatar answered Oct 12 '22 08:10

saravanan