I have a ListView
with items containing each one a SeekBar
.
What I want to achieve is that when one of the SeekBar
s is slowly slided, the rest of the SeekBar
s gracefully slide at the same time (this is, I want the events of one items to make effect on the rest of the list items).
I tried to store all the views in an array of views inside the adapter, but I was getting unexpected and unpredictable behavior (I guess it is related to the way ListView manages the child items internally).
Any hint on how this should be properly done?
Thank you very much!
I would solve the problem using RxJava.
Basically, you have a stream of data (Seekbar
's current position) and have arbitrary amount of subscribers (each Seekbar
of each row).
You need some kind of Observable
, that possesses following features:
Observable
Turns out BehaviorSubject
is the one that you need.
So, having declared a BehaviorSubject
this was:
BehaviorSubject<Integer> subject = BehaviorSubject.createDefault(0); // default value is 0
Now anytime any Seekbar
's value is changed just perform subject.onNext(currentPosition)
.
As soon as the view is being shown on the screen - subscribe to the stream:
Disposable d = subject.subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
seekbar.setProgress(integer);
}
)
When the view is being recycled - dispose from the Disposable
:
d.dispose();