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...
}
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)