MediatorLiveData or switchMap transformation with multiple parameters

前端 未结 4 1171
我在风中等你
我在风中等你 2020-12-13 00:23

I am using Transformations.switchMap in my ViewModel so my LiveData collection, observed in my fragment, reacts on changes of code parameter.

4条回答
  •  伪装坚强ぢ
    2020-12-13 00:37

    I faced a similar problem. There are 2 ways to solve this:

    1. Either use MediatorLiveData
    2. Use RxJava as it has various operators to do such kind of complex stuff

    If you don't know RxJava, then I'd recommend writing your custom MediatorLiveData class. To learn how write custom MediatorLiveData class check out this example: https://gist.github.com/AkshayChordiya/a79bfcc422fd27d52b15cdafc55eac6b

提交回复
热议问题