Questions tagged [mutablelivedata]

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

320 questions
2
votes
1 answer

Android MediatorLiveData source subscription does not trigger

In my project I'm using a slightly modified repository pattern: DataSource (e.g. API, database). Provides CRUD of entities Repository of specific data (e.g. UserRepository, SettingsRepository) that handles reconciliation of DataSources (e.g. update…
fonix232
  • 2,132
  • 6
  • 39
  • 69
2
votes
0 answers

Call function when condition pass - ViewModel, LiveData, Transformations

I want to call a function in a ViewModel which returns nothing when a value is different from 0. Here is the code I have so far, but it doesn't get triggered. val categoryId = MutableLiveData() val waitToCallApi: LiveData =…
Robert Pal
  • 714
  • 1
  • 7
  • 15
2
votes
1 answer

How to fix null pointer for "resp" while observing the value of live data

My code works fine with view model but when I start observing the value using live data in model.d.observe(this, Observer { r->resp=r }) type of r in resp=r is changed from RespCategories to RespCategories? and it…
2
votes
2 answers

Wrapping MutableList in either LiveData or MutableLiveData

What is the recommended means of wrapping a MutableList within either LiveData or MutableLiveData such that one can modify the list and observe the changes it undergoes ? I have some fairly short tables (<20 items) in Room (It caches the values…
Carel
  • 3,289
  • 2
  • 27
  • 44
2
votes
1 answer

How to use livedata for making multiple network calls?

i am working on a project in which i am trying to implement Android architecture components with data binding. I have an activity, viewmodel and repository and i am crating a login page right now. I have to make two repository functions to make the…
2
votes
1 answer

Databinding/Live data handle configuration changes with Retrofit/Rxjava

Please look at this code: Main activity: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MutableLiveData mutableUser = new MutableLiveData<>(); …
user1209216
  • 7,404
  • 12
  • 60
  • 123
1
vote
1 answer

LiveData observer triggered again on fragment back navigation

I am building an Android app that displays a list of categories using a RecyclerView in a Fragment. When the user taps on a category, I navigate to the same Fragment with the child categories of the selected category. If the selected category has no…
Pratik Fagadiya
  • 1,195
  • 7
  • 21
1
vote
1 answer

Why declare mutableLiveData class with val type?

Why not use mutableLiveData of the val type as a substitute for the var type? Isn't it a violation to be able to set on the val type? Like, for example: Example of a val type class LoadDetailViewModel : ViewModel() { private val _liveData =…
1
vote
1 answer

Kotlin MutableLiveData not changing

I have a loginStatus value declared as MutableLiveData: val loginStatus = MutableLiveData() When the user logins, the value will be changed to true in the viewModel: withContext(Dispatchers.Main){ loginStatus.value = true } When…
1
vote
2 answers

How can I track liveData subscription?

I have a problem with liveData. It doesn't update the fragment with the information. I think it unsubscribes from viewLifecycleOwner at some particular moment. Is there a way to track the subscription of liveData and see if it unsubscribes or not?…
1
vote
3 answers

How to add and remove item in MutableLiveData> and notify the UI in kotlin

I want to add and remove items in MutableLiveData>. Adding items to the list is working fine and UI is also updating. But removal from array list is not working properly. @HiltViewModel class SecondViewModel @Inject constructor() :…
1
vote
1 answer

Data not transferring from one fragment to another using ViewModel and LiveData

I have 2 fragments: HomeFragment ListFragment I am trying to send data from HomeFragment to ListFragment using ViewModel and LiveData but i am not able to do so. ListFragment is not updating the value. So i have 2 buttons: Groceries and Electronics…
user20324171
1
vote
1 answer

How to Updating jetpack compose with MutableLiveData.observeAsState() more often

fun Conversation(mainViewModel: MainViewModel) { var stat = mainViewModel.getTweet().observeAsState() val listState = rememberScrollState() stat?.let { if( stat.value == null){ Log.d("DAD","DASSA") // null…
1
vote
1 answer

MutableLiveData, LiveData List empty or add item first position

I don't quite understand the behavior of MutableLiveData or I can't find the proper documentation. But I need help. I need to add an element to the first position of the array and tried with "plus" but it doesn't work properly. Or is there a way to…
kekaben971
  • 13
  • 3
1
vote
1 answer

Problem Implement Update UI with LiveData, Retrofit, Coroutine on Recyclerview : adapter Recyclerview not update

I'm newbie use Kotlin on my dev apps android, and now, I on step learn to implement Update UI with LiveData, Retrofit, Coroutine on Recyclerview. The My Apps: MainActivity > MainFragment with 3 Tab fragment > HomeFragment, DashboardFragment, and…