LiveData which publicly exposes setValue(T) and postValue(T) method.
Questions tagged [mutablelivedata]
320 questions
1
vote
2 answers
Live data observer triggered twice on fragment created
The issue that I have is not actually bug or big problem. And all works as it should, but nevertheless it annoys me.
In Fragment pbserver:
viewModel.pageNumbersPosition.observe(viewLifecycleOwner) {
if (it!=null) {
…

Dim
- 4,527
- 15
- 80
- 139
1
vote
1 answer
Is this a bug relating to LiveData
I have isolated the code to show this problem.
I have a recyclerview inside a fragment. I also have LiveData and MutableLiveData.
In the ViewModel.kt code there are these two lines in this order and it works fine:
private val mMLD =…

EliFromToronto
- 81
- 1
- 8
1
vote
1 answer
MutableLiveData value not updating confusion?
Working on a project in Kotlin in AndroidStudio, fairly basic stuff, but MutableLiveData is not working like I expect it to. Am I doing something wrong or maybe I'm confused on how it works?
I'm using a viewModel to handle the LiveData and for…

Rayge
- 11
- 2
1
vote
1 answer
Convert MutableLiveData to MutableState
I am new to jetpack compose. I have this value which is a MutableLiveData. I want ofc to observe on the object and get the value. I was wondering if i could convert the MutableLiveData to MutableState in an easy way? To make it even simpler, or is…

Meyben
- 451
- 3
- 15
1
vote
1 answer
Observer is called multiple times when DialogFragment is opened with screen rotation changes
I have an activity that implements an observer inside the OnCreate for a MutableLiveData variable that is in a ViewModel.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
…

Luis Botero
- 25
- 4
1
vote
1 answer
Android's MutableLiveData should use nullable objects only?
My simplified code is:
class MyViewModel : ViewModel() {
private val myLiveData: MutableLiveData = MutableLiveData(MyObject())
val myObject: MutableLiveData
get() = myLiveData
fun addItem(item:…

ocramot
- 1,361
- 28
- 55
1
vote
0 answers
How to bound view margin to viewmodel string live data?
Current issue is a bit complicated, so I will outline some words with "" so whoever reads this could be able to understand text below.
I have a "page viewer", which implements "recycler view adapter".
Each page has 4 textviews inside it, i pass text…

LAO
- 87
- 10
1
vote
0 answers
Kotlin MutableLiveData clean or update
I am pulling data from api in my application. I keep the data I have in MutableLiveData. There is no problem so far. However, when I filter and pull other data, it lists the new data under the old data. My goal is to delete the old data and show…

Theodore Bagwell
- 11
- 2
1
vote
1 answer
How do you reset MutableLiveData/LiveData values?
I'm making a trivia game that fetches questions from an API service. I have code like this in my view model.
private var _currentQuestion = MutableLiveData()
val currentQuestion: LiveData = _currentQuestion
fun…

SmallGrammer
- 893
- 9
- 19
1
vote
0 answers
Jetpack compose function is not getting updated when changing the value of livedata in viewmodel
I am trying jetpack compose with ViewModel. Whenever the user clicks on some item I want to select that item and deselect everything else. The problem is if I try to manipulate the same mutable list with the new value it is not working. But if I try…

Chirag Parekh
- 102
- 2
- 7
1
vote
1 answer
Why we need to extend ```ViewModel()``` for DataBinding and LiveData to create LiveData object
Without extending ViewModel() just with simple class I am able to implement LiveData and DataBinding example but I show in google developer doc to extend ViewModel() to create object of LiveData.So why we need to extend…

Purvesh Dodiya
- 594
- 3
- 17
1
vote
0 answers
How to show loader again when using paging Library for Filter/Sort
enter code here
//constructor
ProductsViewModel(String seoUnique) {
// getting our data source factory
ProductsDataSourceFactory productsDataSourceFactory = new ProductsDataSourceFactory(seoUnique,
"");
// getting the live data…

bishal
- 13
- 5
1
vote
2 answers
Observe list of live data in java
I have a list of liveData, like List>. I want to observe this list so that whenever the String inside the LiveData changes, it would notify the observer of the list with this String.
How can I do this?
My list elements are strictly…

Mr. Techie
- 622
- 7
- 17
1
vote
2 answers
Adding an object to a mutable live data list
I am trying to add two shops to a mutable list like so:
private var _shopList = MutableLiveData
- >()
var shopList: LiveData
- > = ()
get() = _shopList
// This function will get the arrayList items
fun…

Lyndon2309
- 49
- 8
1
vote
2 answers
Android ViewModel MutableLiveData update multiple times
Scenario
Hi,
I have an Activity with a ViewPager. In the ViewPagerAdapter, I create instances of a same fragment with different data.
And in each instance I initialize a ViewModel
val dataViewModelFactory = this.activity?.let {…

The Bat
- 1,085
- 1
- 13
- 31