Questions tagged [android-mvvm]

Questions regarding applying a Model-View-ViewModel in android application

773 questions
2
votes
1 answer

How to get room select with livedata?

I'm using room with livedata. when I select from viewmodel, I can't see anything. But when I select directly to dao, I can see items. What's the problem? Room has no mutable livedata so I choosed livadata... but it doesn't work. please help me. I…
user9628944
  • 131
  • 7
2
votes
2 answers

Android MVVM. Passing objects that has Context as dependency

I have a viewmodel that accepts model as one of a constructor parameters. MainModel has context (I need it for registering broadcastReceiver). class MainViewModel(private val test: MyTestReiverHandler) : ViewModel() { } class…
David
  • 3,055
  • 4
  • 30
  • 73
2
votes
0 answers

Where to put the FirebaseAuth.AuthStateListener in MVVM?

I'm learning how to login firebase with MVVM and I don't know where to put AuthStateListener. I placed login and registration in the repository, but I don't know where to place the AuthStateListener according to the MVVM pattern. I was thinking…
beginner992
  • 659
  • 1
  • 9
  • 28
2
votes
1 answer

Dagger 2, BottomNavigation and Injecting

I am doing the small Android app in MVVM and Dagger 2. But I don't know how to correctly use Dagger 2 in case when I have the one Activity and two Fragments. Both Fragments are owners of the ViewModels. I've injected ViewModelProvider to Fragment,…
beginner992
  • 659
  • 1
  • 9
  • 28
2
votes
0 answers

Viewmodel get's recreated on configuration change

I am seeing my Viewmodel getting created every time I do an orientation change. I always thought the ViewModelProviders would give me back the same instance of the on config changes. I initalize my view model in onActivityCreated . I am using a…
2
votes
1 answer

Room Database : RecyclerView does not update after delete data in detail activity

I'm using RecyclerView for showing list of favourite movie, when user click on item in my RecyclerView list, it will open DetailActivity, and in this Activity user can remove data from favourite list. when user click onBackPressed in DetailActivity,…
Menma
  • 799
  • 1
  • 9
  • 35
2
votes
0 answers

Android Kotlin Coroutines fetching data with chained network requests

Q) How can I update my viewModel per item using chained network requests using coroutines? I'm trying to fetch some objects from an api, but the api requires an initial call to fetch an array of objectIds, and then each object is fetched with an…
2
votes
1 answer

Two way binding cannot resolve a setter

I am trying to learn about data binding I have my CreditCardViewModel class which is bind in my fragment as follows public class CreditCardValidatorFragment extends Fragment { private CreditCardViewModel cardViewModel; private…
2
votes
0 answers

How to get values from EditText on Button click using Data Binding in android?

activity_login.xml In my layout file there are total 3 fields. 2 edittext and 1 button I want to get values from edittext on button click
2
votes
2 answers

How to display items in RecyclerView running inside Fragment using MVVM?

I am trying to implement recyclerview in a fragment using MVVM but the items are not loading on the screen. Here's the code: BlankFragment.java: package com.phunware.example.mvvmrecyclerviewblog; import android.content.Context; import…
sak
  • 1,230
  • 18
  • 37
2
votes
1 answer

Android databinding click listener not working(work randomly)

My click listener are not working even if I check with a Toast inside of them, it use to work but after I made a couple of change in my viewModel it stop working, I can't figure out what went wrong. This happen in my detail activity only, but work…
2
votes
0 answers

Where should I parse data from intent (when NFC tag is scanned), in Activity or in ViewModel?

I'm developing an app which is supposed to display different content based on information which comes from NFC tag. The basic idea: User scans NFC tag -> Android sends Intent -> my activity receives the intent -> parse NFC data from intent -> fetch…
SergeiTonoian
  • 341
  • 2
  • 13
2
votes
3 answers

andorid- how to access context or sharedprefences in model class MVVM

I need to access sharedPrefences in my model class since we shouldn't access context and views from model class, How can I get a value from the model? I don't want to parse each of my variables to viewmodel and then my model class. model class:…
2
votes
1 answer

SwipeRefreshLayout's onRefreshListener doesn't work on databinding mvvm android

I want to refresh a list of elements by using MVVM and data binding but SwipeRefreshLayout doesn't work on XML layout. BaseViewModel.java public class BaseViewModel extends ViewModel { private final DataManager mDataManager; private…
2
votes
1 answer

Android MVVM where to store data?

I have an activity with 4 fragments, on each of the fragments the user inputs a string and then moves on to the next one. So far I have a viewModel for every fragment and I pass each input as an argument that then I store in the viewModel. My…
Jose Gonzalez
  • 1,491
  • 3
  • 25
  • 51