Questions tagged [mutablelivedata]

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

320 questions
2
votes
0 answers

Performace overhead when creating too many mutable livedata in a viewmodel

I wanted to know if there could be any performance issue if we create too many mutable live data objects in single viewmodel? in recent project I saw too many mutable live data objects in a viewmodel which I saw first time and made question…
blackHawk
  • 6,047
  • 13
  • 57
  • 100
2
votes
1 answer

How to extract the information from MutableLiveData> to a simpler object in viewmodel

I am trying to get an object from a MutableLiveData> to a var hereIwantTheObject : ObjectIWant in my HomeFragment, apparently use the Resource class is the recommended way if you use coroutines and LiveData. The thing is that I…
Tony
  • 159
  • 1
  • 11
2
votes
4 answers

How to use Single Live Event to show toast in Kotlin

I want to use single live event class to show toast (like flag) Here is my code what I tried. I want to not use peding like flag. how do I fix it? MainViewModel class MainViewModel(private val movieRepository: MovieRepository) : ViewModel() { …
Mj choi
  • 69
  • 1
  • 9
2
votes
2 answers

How to use LiveData for searching?

I have a ViewModel that has a MutableLiveData of an arraylist of class Course private var coursesList: MutableLiveData> = MutableLiveData() This coursesList is filled with data got from an API (by Retrofit):…
2
votes
2 answers

LiveData type mistmatch in ViewModel

I was following one of the UDACITYs Android Tutorial on LiveData/Room/Persistence and Repository Architecture. After gluing the codes all together, I came across (what I believe, a very common issue) Type Mismatch exception. On the course example, a…
mirageservo
  • 2,387
  • 4
  • 22
  • 31
2
votes
3 answers

Why are MutableLiveData variables declared with equals sign (=)?

In Kotlin, when declaring the type of variable, a colon is used. Even when declaring LiveData, a colon is used. So why is an equals sign used for MutableLiveData? I haven't been able to figure this out. I spent about 2 hours a few days ago trying to…
2
votes
1 answer

how to use the same mutableLiveData in ViewModel from fragment and dialog fragment

I have a ViewModel, that I used in Fragment and DialogFragment. In Dialog Fragment, I try to update MutableLiveData value in Dialog Fragment and then use that value from MutableLiveData in my Fragment. as I check In Dialog Fragment I have data…
2
votes
2 answers

LiveData with two sources?

I'd like to use the same LiveData with different sources. One from an API call which is an observable and one from a database which is a LiveData. I'd like to be able to do something like this: private LiveData> items = new…
2
votes
1 answer

Can't Observe LiveData from ViewModel in Fragment

I have a RecyclerView in my ViewPager's one of the Fragment. This RecyclerView show's data that are fetched from Server. It normally works, but I couldn't be able to implement the same feature using ViewModel and LiveData, because the…
2
votes
1 answer

Mutable Live Data Value is updated on creation of fragment

I have rigged up a simple login fragment with a view model. Here is the fragment : class LoginFragment : Fragment() { companion object { fun newInstance() = LoginFragment() } private lateinit var viewModel: LoginViewModel override fun…
2
votes
2 answers

MutableLiveData with initial value from LiveData

I have a situation where I have a view model for a page that is rendered based on some input data (id) with fields that are initialized from my repository but can be edited by the user. My repository function is pretty straightforward: class…
sohum
  • 3,207
  • 2
  • 39
  • 63
2
votes
1 answer

Understanding LiveData and DataBinding

I am new to android development and MVVM and try to understand Databinding and LiveData. With one-way-DataBinding you can get Data from the viewmodel to the view. With two-way-DataBinding you can get Data from the viewmodel to the view and from…
user11812815
2
votes
2 answers

How to make data binding work with xml attributes?

I'm setting up my Edittext and CheckBox to hook with my view model. I've already setup the variables isActive and currentValue on my ViewModel, and I want to initialize their values to the xml so that when the user arrives at the Fragment, the…
2
votes
5 answers

Problem with Databinding and MutableLiveData

NOVEMBER 2019 UPDATE - it is working as intended now on the latest version. ORIGINAL POST: I'm binding MutableLiveData to my SwipeRefreshLayout via publicly exposed function setRefreshing (app:refreshing in XML) and everything works fine by the…
2
votes
1 answer

ViewModel and LiveData are not deleted after the application is closed. Why?

I just started learning android development and I had a problem, I’m happy to get any help. When I click the "User exists?" Button, a request is sent to the server and the server returns either a user or null (in my case, always null, because no…