I'm trying to loop a list but i'm not getting the index of current item.
Observable.fromIterable(yourList).observeOn(Schedulers.io()) .observeOn(Schedulers.io()).subscribe( { item -> { }}, {_ ->{}}, {->{}}
Is there any way to get index just like
yourList.forEachIndexed{ index, item -> }
I already know that
class Indexed { int index; String element; Indexed(int index, String element) { this.index = index; this.element = element; } }
this can be used as a solution. But i don't like this kind of approach. I want to know whether Rxjava itself has something for it.
您可以这样使用Iterable.withIndex()
:
Observable.fromIterable(yourList.withIndex()) .observeOn(Schedulers.io()) .subscribe( { (index, item) -> {} }, { _ -> {} }, { -> {} } )