My onProgressChanged()-event doesn't get fired when I set the progress of a SeekBar programmatically, but it does get fired perfectly fine when I physically move the SeekBar slider.
I'd expect the event to fire when using setProgress() - the Android Developer Reference even states that:
public abstract void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser)
Notification that the progress level has changed. Clients can use the fromUser parameter to distinguish user-initiated changes from those that occurred programmatically.
Some code snippets from my project:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
final SeekBar mySeekBar = ((SeekBar) findViewById(R.id.mySeekBar));
mySeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// Do some stuff
}
}
}
@Override
protected void onResume() {
super.onResume();
final SeekBar mySeekBar = ((SeekBar) findViewById(R.id.mySeekBar));
mySeekBar.setProgress(someValue); // This SHOULD trigger onProgressChanged(), but it doesn't...
}
We can get the current progress value from a Seekbar in java class using getProgress() method. This method returns an integer value. Below code is used to get the current progress value from a Seek bar.
Android SeekBar is a kind of ProgressBar with draggable thumb. The end user can drag the thum left and right to move the progress of song, file download etc. The SeekBar. OnSeekBarChangeListener interface provides methods to perform even handling for seek bar.
↳ android.widget.SeekBar. A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys.
Stumbled across the same problem just now.
In my case, the onProgressChanged
did not get fired simply because the value did not actually change. I was setting the same value as the current one (0
:)
(and I don't see anything wrong with your code)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With