I'm beginning to learn RxJava. I have an array of Views that I want to set an OnClickListener
to each of them using ViewObservable.clicks()
. The implementation of the OnClickListener
will just call a method that depends on the position of the view in the array (e.g.: populate(viewPositionInTheArray)
).
An imperative solution will be this one:
for (int i = 0; i < views.length; i++) {
final int finalI = i;
view[i].setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
populate(finalI);
}
});
}
In order to do that using RxJava, I guess I'll need to do some stream chaining. However, I have no idea what functions I must use in an elegant, FRP way of doing it. Any suggestions?
Thanks
Here's my stab at it. I ussualy use range operator when I need to maintain index through observable change