Skip to content Skip to sidebar Skip to footer

Android Architecture Components Livedata

I'm trying to implement a simple App using Architecture Components. I can get the info from RestApi services using Retrofit2. I can show the info in the respective Recyclerview an

Solution 1:

I'm more familiar with doing this in Kotlin but you should be able to translate this to Java easily enough (or perhaps now is a good time to start using Kotlin :) )....adapting similar pattern I have here I believe you'd do something like:

val query: MutableLiveData<String> = MutableLiveData()

val  mList = MediatorLiveData<List<ItemList>>().apply {
    this.addSource(query) {
        this.value = meliRepository.getItemsByQuery(query)
    }
}

funsetQuery(q: String) {
    query.value = q
}

I'm using this pattern in following https://github.com/joreilly/galway-bus-android/blob/master/app/src/main/java/com/surrus/galwaybus/ui/viewmodel/BusStopsViewModel.kt

Post a Comment for "Android Architecture Components Livedata"