Questions tagged [mediatorlivedata]
42 questions
7
votes
2 answers
LiveData with filters?
I'm new to LiveData and I've been doing some tests lately. I have an app where I need to display data that can be filtered (name, category, date...). The filters can be combined too (name + date). This data comes from an API call with Retrofit +…

unadivadantan
- 363
- 4
- 14
7
votes
3 answers
How to remove an observer from livedata so it doesn't show twice when navigating back to the fragment
I have a fragment which displays a popup when the user is successfully logged in. If I navigate to a new fragment and come back, the popup with the previous username is shown again. I fixed this problem using SingleLiveEvent, but I now have to…

Vera
- 73
- 1
- 4
4
votes
1 answer
LiveData transformations map functionality
Recently i've been learning transformations methods on LiveData
I know that we can use map or switchMap method to transform livedata.
Let's say we have Player data class similar below
data class Player(val name: String, val score: Int = 0)
And we…

nasibeyyubov
- 1,735
- 3
- 11
- 28
3
votes
1 answer
Which is a better way to combine multiple LiveData(s): using MediatorLiveData or switchMap?
Which approach is more recommended to combine multiple LiveData(s): using MediatorLiveData or switchMap?
// MediatorLiveData approach
fun combine(
liveData1: LiveData,
liveData2: LiveData,
onChanged: (A?, B?) -> C
):…

Tatsuya Fujisaki
- 1,434
- 15
- 18
3
votes
0 answers
Android LiveData>: How to merge two data sources of similar objects
I have a super class called Transaction {} and have two other classes that extend it called
InTransaction and OutTransaction.
InTransaction links to another Room entity called Source and OutTransaction links to another entity called Category.
I am…

TheRealChx101
- 1,468
- 21
- 38
2
votes
1 answer
Add multiple source to MediatorLiveData and change its value
Basically I have a screen, and there are a few EditTexts and a Button.
Users have to fill in all fields otherwise the Button is disabled.
I am using DataBinding to achieve this. Below is my code in the viewmodel.
val isNextEnabled =…

Hayton Leung
- 97
- 1
- 1
- 8
2
votes
2 answers
LiveData with two sources?
I'd like to use the same LiveData with different sources. One from an API call which is an observable and one from a database which is a LiveData. I'd like to be able to do something like this:
private LiveData
- > items = new…

unadivadantan
- 363
- 4
- 14
2
votes
1 answer
Android mediator live data combine 2 live data into one stream and one trigger
I have 2 live data, I add them as sources to a mediator live data, I expose this from a view model for a fragment to observe.
When either of the live data changes it triggers the onChanged method of the mediator live data, which means my observer…

martinseal1987
- 1,862
- 8
- 44
- 77
1
vote
0 answers
Kotlin. Get two firebase queries in one viewmodel
There are multiple RecyclerView in my application. Each one consists of the same records, but with different filters.
For example, the first RecyclerView contains new records, the second RecyclerView contains the most popular, etc.
I am trying to…

Boris Grebennikov
- 11
- 1
1
vote
0 answers
LiveDataReactiveStreams.fromPublisher() not working with Single
I am getting User from Room Database by returning Single. Once I get the data I want to show it through LiveData observing, and I am using LiveDataReactiveStreams.fromPublisher() method, but looks like when .setValue() is called, all…

mantc_sdr
- 451
- 3
- 17
1
vote
0 answers
Android MediatorLiveData removeSource not working
I am using MVVM + LiveData + Dagger 2.27 on my app.
i am trying to call 2 APIs at the same time.
viewModel.getMyPendingUnits()
viewModel.getMyApprovedUnits()
and I am using MediatorLiveData to combine 2 observers
val approvedUnits =…

Mohammad Sommakia
- 1,773
- 3
- 15
- 48
1
vote
1 answer
MediatorLiveData onChanged not called although it's being observed
In NetworkBoundResource file, until the line "Log.d(TAG, "init: called")" gets worked, but
results.addSource not work although I am observing it in my RestaurantViewModel class, and the other MediatorLiveData which observes the results in…

Vics
- 11
- 2
1
vote
1 answer
Merging different depending LiveData objects into one
Here is my problem.
I have to generate data from three different LiveData objects into one object. Two of them depending of one of them. The observer should only be triggered if all three object data was received.
Here is an example:
The resulting…

Manuel Siebeneicher
- 95
- 7
1
vote
0 answers
Nested transformation instead of merged livedatas
I have two livedatas startedAt & finishedAt and want to use them in a transformation that depend on both these values...i tried combine them using mediatorliveData
fun LiveData.combine(other: LiveData): PairLiveData {
…

joghm
- 569
- 3
- 20
1
vote
2 answers
Transformations.map() returns null values
I am writing a program in which i have two LiveData objects as shown:
public LiveData chosenImages;
public LiveData
- > chosenBitmaps= Transformations.map(chosenImages, (placeimags) ->
{
ArrayList

neonpokharkar
- 96
- 11