Questions tagged [android-livedata-transformations]
30 questions
26
votes
3 answers
Unresolved reference: Transformations after upgrading lifecycle dependency
After upgrading the lifecycle dependency from 2.6.0-alpha04 to 2.6.0-beta01 I got Unresolved reference: Transformations and it can't import androidx.lifecycle.Transformations class.
import androidx.lifecycle.Transformations
...
var myList:…

Zain
- 37,492
- 7
- 60
- 84
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
4
votes
1 answer
Android LiveData: Difference between LiveData provided as method or as variable
I am facing a strange, but huge difference in behaviour between observing LiveData that is exposed as a method and LiveData that is exposed as variable. Consider the following code in your ViewModel:
LiveData as method
private val carApiCall =…

muetzenflo
- 5,653
- 4
- 41
- 82
2
votes
0 answers
Transformations not importing in Android studio
I am trying to add currency symbol with the cost using Transformations of Live Data object, but it is not importing.
private val _price = MutableLiveData()
val price: LiveData = Transformations.map(_price) {
…

Rishabh Aggarwal
- 19
- 5
2
votes
2 answers
Why each activity is getting update to the original live data instead of recent live data?
MeetingViewModel
fun observeAttendeesJoined(): LiveData>? {
return Repository.getAttendeesJoined()
}
There is a singleton repository using kotlin's object declaration.
Repository has a live data which is being…

Sagar Patel
- 506
- 1
- 8
- 23
2
votes
1 answer
Android LiveData in Transformation map is null
I am facing and issue with Android LiveData and Transformation map. I am gonna explain the case:
I have a SingleLiveEvent and LiveData as follows (one for all items and another one for items to display in screen):
val documents:…

Alejandro
- 102
- 9
2
votes
0 answers
How to change a LiveData value based on two others LiveData values from a ViewModel
I want to change a LiveData value based on two others LiveData values but I don't know how to do it.
I know that I can use LiveData.map() but that only works if I want to change a LiveData value based on another LiveData value.
I have a Repository…

Marti Serra Molina
- 423
- 3
- 11
1
vote
1 answer
Why declare mutableLiveData class with val type?
Why not use mutableLiveData of the val type as a substitute for the var type?
Isn't it a violation to be able to set on the val type?
Like, for example:
Example of a val type
class LoadDetailViewModel : ViewModel() {
private val _liveData =…

LineSmile
- 25
- 4
1
vote
2 answers
Access Room DB inside Transformation.map android
In my Database i have a table called Account which looks kinda like this
@Entity(tableName = "accounts", primaryKeys = ["server_id", "account_id"])
data class Account(
@ColumnInfo(name = "server_id")
val serverId: Long,
…

james04
- 1,580
- 2
- 20
- 46
1
vote
1 answer
Live Data issue inside Loop
I have an IOTCamera function inside viewModel with Loop. The function should repeatedly call the repository GET function based on the "selectedSlot" parameter with a delay of 1 minute. My problem here is the loop(repeat()) is not working properly.…

Nithinjith
- 1,775
- 18
- 40
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
0
votes
0 answers
Transformation error after Kotlin Migration
I haven't touched this source code for half a year. Recently, before I touched anything, I decided to update the following: AGP, Gradle, dependencies and Kotlin Migration.
Code:
Placeholder Fragment
class myPlaceholderFragment : Fragment() {
…

Kellin Strook
- 487
- 1
- 5
- 18
0
votes
0 answers
Transformations.map not getting triggered immediately
Here's the snippet to demonstrate the problem:
ViewModel code:
class SampleViewModel : ViewModel() {
private String someData = ""
private lateinit var _selectedString: MutableLiveData
val selectedString: LiveData get()…

Hari Kiran
- 9
- 1
0
votes
1 answer
How to transform LiveData> to LiveData>
- >
My project is an expense tracker where I show a list of Dates under which I have a list of expenses that happened on those dates. I have nested RecyclerViews. Parent RecyclerView is a list of unique dates of all expenses. Child RecyclerView is list…

Karolis
- 53
- 5