所以我找到了合适的解决方案。可以在一个 observable 本身中捕获所有 seekbar 回调。下面是解决方案
科特林
RxSeekBar.changeEvents(seekbar)
.observeOn(AndroidSchedulers.mainThread())
.subscribe { seekBarChangeEvent ->
when (seekBarChangeEvent) {
is SeekBarProgressChangeEvent -> Log.d(TAG, "on Progress : " + seekBarChangeEvent.progress())
is SeekBarStartChangeEvent -> Log.d(TAG, "on Start : ")
is SeekBarStopChangeEvent -> Log.d(TAG, "on Stop : ")
}
}
爪哇
RxSeekBar.changeEvents(seekbar)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(seekBarChangeEvent -> {
if (seekBarChangeEvent instanceof SeekBarProgressChangeEvent)
{
SeekBarProgressChangeEvent seekBarProgressChangeEvent = (SeekBarProgressChangeEvent) seekBarChangeEvent;
Log.d(TAG, "on Progress : " + seekBarProgressChangeEvent.progress());
}
else if (seekBarChangeEvent instanceof SeekBarStartChangeEvent)
{
Log.d(TAG, "on Start : " );
}
if (seekBarChangeEvent instanceof SeekBarStopChangeEvent)
{
Log.d(TAG, "on Stop : " );
}
});