Questions tagged [mutablelivedata]

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

320 questions
0
votes
1 answer

How to use livedata to send data from service to activity?

How with livedata can i send some data from a service to the main activity and (the most important), how can I know that a main activity was actually observing this data so that I m sure I didn't sent the data nowhere?
zeus
  • 12,173
  • 9
  • 63
  • 184
0
votes
1 answer

Observing data from Base ViewModel in extended Fragment is not working

I have a BaseFragment and BaseViewModel. I created HomeFragment that extended from BaseFragment. Now I observe a LiveData of BaseViewModel but observing data is not working. // BaseFragment abstract class BaseFragment
nauq
  • 1
0
votes
0 answers

How to properly work with collections in ViewModel and get notified?

I have ViewModel with property like this: private val _items = MutableLiveData>(ArrayList()) // this is private to ViewModel val items: LiveData> get() = _Items // I'm observing this from my…
Kamil
  • 13,363
  • 24
  • 88
  • 183
0
votes
1 answer

Can ViewModel observe its MutableLiveData property?

I'm trying to use ViewModels with LiveData and MutableLiveData in Android for the first time. I have not read all documentation yet. My question: How can I call fun applyFilters() when val filterByName = MutableLiveData() was changed from…
Kamil
  • 13,363
  • 24
  • 88
  • 183
0
votes
1 answer

Observing live data from an API is not updating ui when data changes

I am trying to develop a football app demo. Data comes from an API from the api It loads data as expected when app started, but when score of match changes, ui is not updating for scores by itself. I am using DiffUtil getChangePayload() to detect…
0
votes
1 answer

convert boolean value into MutableLiveData

var booleanresult : MutableLiveData? = null fun checksubcat() = viewModelScope.launch(Dispatchers.IO) { val trueorfalse : Boolean = productsDao.getSubCatId(subcat_id) booleanresult?.value = trueorfalse Log.e("update","view…
0
votes
0 answers

Subscribe to updates LiveDate in delegate

I have a ToolbarDelegate delegate that manages the state of the toolbar. I need to pass some LiveData values ​​from ViewModel to delegate ToolbarDelegate - onlineStatusLiveData, userNameLiveDate, groupLiveData The problem is that at the time of…
0
votes
1 answer

In Kotlin Android, viewModel has no observer

I made a toolbar in a BaseActivity to implement a common and the code is as follows. // BaseActivity abstract class BaseActivity : AppCompatActivity() { lateinit var cartCnt: TextView private val viewModel by lazy { …
Jun
  • 451
  • 4
  • 16
0
votes
1 answer

java.lang.NullPointerException:Attempt to invoke virtual method 'void androidx.lifecycle.MutableLiveData.postValue(java.lang.Object)' on a null object

My ViewModel class @HiltViewModel class RandomRecipeViewModel @Inject constructor( val repo: RecipesRepo, val app: MyApplication ) : AndroidViewModel(app) { init { getRandomRecipes() } val randomRecipe =…
0
votes
1 answer

Android MutableLiveData.value = getNewValue() does not work

Why it's not possible to directly set the mutableLiveData.value when using a suspend function? See following code: private val _clubs: MutableLiveData> by lazy { MutableLiveData>().also { …
David
  • 3,971
  • 1
  • 26
  • 65
0
votes
1 answer

Recyclerview move to penultimate position when the list is update

Currently i have the next config. RecyclerView + MutableLiveData + DiffUtils The behavior is: When i move to the last position and update the list, the RecyclerView move automatically to penultimate item, but only happen with the last position
0
votes
1 answer

How to add items to MutableLiveData arraylist?

I have a MainViewModelwith the code: private val locationList: MutableLiveData> = MutableLiveData() fun getLocationList(): MutableLiveData> = locationList and a fragment where I am trying to add values to the…
zeppal
  • 181
  • 7
0
votes
1 answer

MutableLivedata observer triggers only value is changed

class MainViewModel :ViewModel(){ private val _text = MutableLiveData() val text get() = _text.distinctUntilChanged() fun setToA(){ _text.value = "A" } fun setToB(){ _text.value = "B" } } I'm…
sooyeon
  • 488
  • 1
  • 5
  • 16
0
votes
2 answers

Problem Implement LiveData : Observe always called when resume fragment (backstack from another fragment)?

I on step learn to implement LiveData in My Apps. My App have one MainActivity with 2 fragment with navigate listner. ListFragment and DetailListFragment. I call function to get data from server on onCreateView ListFragment by viewModel, and observe…
0
votes
1 answer

Change background color of a Fragment from DialogFragment ColorPicker using Mutablelivedata not working

My app should be able to change color of one part of my screen in a Fragment (called Color Preview) from Color Picker that is DialogFragment and appears once a Button is clicked. I used the same ViewModel with MutableLiveData in it within Fragment…