Questions tagged [mutablelivedata]

LiveData which publicly exposes setValue(T) and postValue(T) method.

320 questions
1
vote
0 answers

LiveData and Transformations.switchMap crashing

I've got an app where I want to add a status of some sort, and if added, I want my UI to show a snackbar saying it was added. I've got a repository, where I add my status. If successful, I'll post the value back to my ViewModel. Since it's a…
Mikkel Larsen
  • 876
  • 2
  • 14
  • 26
1
vote
1 answer

Android Two-Way Data Binding Observer Called Twice

I am learning to use data binding from the following example: https://github.com/ResoCoder/databinding-with-livedata-tutorial In particular, I'm having trouble with the following…
1
vote
1 answer

Is it better to expose the LiveData object as a parameter of the ViewModel or rather returned by a member function call?

Usually MutableLiveData is used in the ViewModel and then the ViewModel only exposes immutable LiveData objects to the observers. https://developer.android.com/topic/libraries/architecture/livedata#update_livedata_objects Is it better to expose…
1
vote
1 answer

Android Architecture Component(LiveData): How to clear all value from LiveData once it updates a textview

suppose I created mutableLivedata variable(an observer), and I updated a textview through it, now I wouldlike to clear value that was sent by livedata once it updates textview like I just created Livedata variable and its fresh in initial stage, it…
1
vote
0 answers

Is it possible to use MutableLiveData with an array of object?

There's a fragment on the app I'm working on that the user needs to fill up to 6 EditText. Each pair of EditText represents the type and description of the user's address (as in "Apartment" as the Type and "1201" as the description). According to…
1
vote
0 answers

Strange Behavior ViewModel Observer Calling Method In Activity - MVVM Architecture

Sorry if my english is bad I'm new in mvvm architecture. I use Room, Dagger, and Reactive. In my project, i create sample with insert 'task' into database and get 'task' from database. the problem is when I save 'task', method in observer for get…
Dhinx
  • 105
  • 1
  • 7
1
vote
1 answer

Reacting to LiveData change within same ViewModel

I have a base ViewModel extended by other ViewModels: abstract class BaseViewModel : ViewModel() { protected val _state = MutableLiveData() protected val state: LiveData = _state ... } I'd like to be able to react…
liminal
  • 1,144
  • 2
  • 13
  • 24
1
vote
1 answer

Passing value to LiveData in Android

I'm new in development and I'm aware that stack isn't for 'full code requests'. But I'm stuck and can't find the solution. I'm using Room database which has two columns - firstName and lastName. I'm loading the database with passed firstName…
1
vote
2 answers

Why is onChanged not called when value changed in LiveData List?

Context Using MutableLiveData> to hold a values. When the first value (using first value as example for brevity) in the List is incremented, TextView should update in onChanged to display the first value in the List. Goals Increment…
surajs02
  • 451
  • 7
  • 18
0
votes
1 answer

Compose UI not updating the state after updating the view model

I am trying to update a compose UI view based on the state changes in the view model, below is my code Initially i am making assigning and doing operation by the default value from view model to a compose logic handling and after some time I will be…
0
votes
0 answers

My DialogBox get called many times when using livedata android kotlin?

I am trying to show DialogBox when my response is received using repository -> ViewModel -> Livedata -> UI. Basically I am using data flow from repository to viewModel to Ui using livedata. But I am using Sealed class also in my ViewModel for…
0
votes
0 answers

What to do if RVA is a LiveData but multiple observers are pointing to it to call notify.....()

So I have a LiveData RVA (Recycler View Adapter), along with an ArrayList(), all of which are MutableLiveData. However, I need to let the RVA know when the ArrayList()'s are updating, so I need to call notifyItemInserted, notifyItemRangeDeleted,…
0
votes
2 answers

How complex should a ViewModel class be?

So far, I have two different ViewModel classes in my project: one that handles login and registration, and another one (HomeViewModel) that handles everything else. The HomeViewModel class is almost 500 lines long and has nearly 30 MutableLiveData…
0
votes
1 answer

Kotlin better readability of MutableLiveData Observer

I would like to make my code more readable by simplifying the observers of the MutableLiveData objects. But I'm not really sure how to do that. I thought about moving the contents of each observe method into a separate class, but that would only…
Kleini
  • 57
  • 7
0
votes
0 answers

After the third change in Wear OS, why am I only getting the initial value?

These are my first steps to create an app for a WearOS watch. I don't unterstand why these little program works for the first and second click. After the third click every click show the right text but after a second it switches back to first…