I have primary and secondary progress growing in the same time, secondary progress grows faster than primary. Everytime I update the primary progress, the secondary one is lost (like it would be zero or less than primary). This produces a nasty flickering.
The only workaround I found is set the secondary to itself after setting the primary. I added "+1" as SeekBar has a check and doesn't redraw if I set the same value.
mSeekBar.setProgress(newPosition);
mSeekBar.setSecondaryProgress(mSeekBar.getSecondaryProgress()+1); // WTF?
The second line may fix it, but it looks ridiculous and I guess inefficient too.
This happens on Lollipop (5.0.1) - API 21. It used to work fine before - can't figure out why.
If I build for API level 19 it works fine. (video: API19Seekbar)
targetSdkVersion 19
compile 'com.android.support:appcompat-v7:19.+'
If I build for API level 21 it flickers. (video: API21SeekBar)
targetSdkVersion 21
compile 'com.android.support:appcompat-v7:21.+'
Full example Activity code follows:
int delay1 = 1000;
int delay2 = 200;
int primaryProgress;
int secondaryProgress;
boolean mStarted;
Button mButton;
SeekBar mSeekBar;
Handler h1 = new Handler();
Handler h2 = new Handler();
Runnable primary = new Runnable() {
@Override
public void run() {
primaryProgress = (primaryProgress + 1) % 100;
mSeekBar.setProgress(primaryProgress);
h1.postDelayed(primary, delay1);
}
};
Runnable secondary = new Runnable() {
@Override
public void run() {
secondaryProgress = (secondaryProgress + 1) % 100;
mSeekBar.setSecondaryProgress(secondaryProgress);
h2.postDelayed(secondary, delay2);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton = (Button)findViewById(R.id.button);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonClick();
}
});
mSeekBar = (SeekBar)findViewById(R.id.seekBar);
}
private void buttonClick() {
mStarted = !mStarted;
if (mStarted) {
mButton.setText("Started");
h1.postDelayed(primary, delay1);
h2.postDelayed(secondary, delay2);
} else {
mButton.setText("Stopped");
h1.removeCallbacks(primary);
h2.removeCallbacks(secondary);
}
}