Questions tagged [mutablelivedata]

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

320 questions
1
vote
2 answers

LiveData in MVVM pattern with retrofit kotlin

I am new to MVVVM and retrofit i have successfully implemented MVVM and is able to move data from retrofit to repository then Repository to ViewModel and view. While doing this i came up to a massive confusion which is mentioned below. In first…
Harry Sharma
  • 2,190
  • 2
  • 15
  • 41
1
vote
1 answer

Android kotlin : mutable live data change not reflecting/updating the layout using data binding in xml

I have created sample project to use the Android data binding with xml layout. Also used MVVM with mutable live data. Screen Layout has a switch widget and linear layout in same layout. I am just trying to hide/show the linearlayout on state change…
1
vote
1 answer

Is there any solution to observe a MutubleLiveData's state in View while it is changed through method's perameter in ViewModel

MutableLiveData's state is not observed in Fragment while I pass a reference of its(MutableLiveData) instance through a method in ViewModel. Only http call is happened and value is shown in log, NO action corresponding LiveData's State is not…
Aminul Haque Aome
  • 2,261
  • 21
  • 34
1
vote
2 answers

Post multiple MutableLiveData have no order

I'm using multiple MutableLiveData on an MVVM architecture. on the ViewModel, I post the objects but the fragment is not resumed. when the fragment has resumed the observers get the MutableLiveData but not in the order I post them. How can I force…
ohad.k.k
  • 11
  • 4
1
vote
1 answer

Run code in main thread when IO thread dispatch completes?

I'm working with livedata. I want to run some arbitrary code in IO and then once that has completed, run some arbitrary code in the Main thread. In JavaScript, you can accomplish something like this by chaining promises together. I know Kotlin is…
user1713450
  • 1,307
  • 7
  • 18
1
vote
2 answers

Android - LiveData doesn't get updated

In my fragment I observe dbQuestionsList field: viewModel.dbQuestionsList.observe(viewLifecycleOwner, Observer { list -> Log.i("a", "dbQuestionsList inside fragment = $list ") }) In my fragment I have few buttons and depending…
1
vote
4 answers

MutableLiveData ArrayList is empty even after postValue() Kotlin

I am now stuck and currently wondering why my mutable arraylist returns null even if it is being updated with postvalue(). I tried to display it using Toast and it displayed [] which I think is null. It had no space in between so it looked like a…
CoderUni
  • 5,474
  • 7
  • 26
  • 58
1
vote
1 answer

Pass multiple Filters to Android Room Dao SQL Query from ViewModel with Repository

I am using the below to fetch Database rows to my Adapter, however I want to return rows from multi-filtered single query using either "LIKE" and/or "WHERE" and basically all sql query filter types, I can do one filter via…
BENN1TH
  • 2,003
  • 2
  • 31
  • 42
1
vote
1 answer

Why my ViewModel is not calling the .observe() and notifying the Adapter ,if the MutableLiveData is changing?

EDIT: The real problem was that the submitList() was not triggering the onCreateViewHolder() in the recyclerView. Solution: I see people keep having issues with this. The android DiffUtils does not work with same instances of a List, if the same…
1
vote
0 answers

How can I make my edit text survive configuration changes, with using viewmodel and without using databinding

I have created a login screen. If I type something on my edit text and rotate my device, the data gets lost. How can I make my edit texts, survive these changes? I have created a loginViewModel in which I am just fetching the data from the api. Here…
MukulCode
  • 97
  • 11
1
vote
1 answer

LiveData update values when field of object change

Today I'm trying to use a LiveData (MutableLiveData) object to have some dynamics values. (in MVVM pattern) I used a model object like this: public class Object { private String name; private float internalvalue; private float in1; …
1
vote
1 answer

How to change particular property value of a class in a LiveData> (in my case LiveData>) using MediatorLiveData

The Item.kt class is @Entity(tableName = "item") class Item( val id: Long, val title: String, ) { @Ignore var selection: Boolean = false } Then i make a query to get all the items in the table ,it return…
1
vote
0 answers

Static Key in ViewModel

There is a project written by another programmer. And in it there is such a code class CardsViewModel : ViewModel() { val selected = MutableLiveData() companion object { @JvmStatic var keyId = 0 } } Every…
Sergei Buvaka
  • 551
  • 1
  • 5
  • 16
1
vote
0 answers

LiveData is not updating after the first call in Android Java

I'm trying to build an app to fetch list of feed from server and display in Recyclerview. I am trying out basic implementation of LiveData like this. I have set up an observer in my Fragment as follows: viewModel =…
1
vote
1 answer

MutableLiveData does not notify observer

I am trying to use MutableLiveData with pre-filled value from database, but Observer always returns null as book. I need to keep it as MutableLiveData, NOT LiveData, because I have to set it programatically on some places. Therefore I am calling…
Tom11
  • 2,419
  • 8
  • 30
  • 56