Questions tagged [android-mvvm]

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

773 questions
3
votes
2 answers

How to use data from onActivityResult in MVVM architecture?

How to use data from onActivityResult in MVVM architecture? I need to add an item to the RecyclerView that is subscribed to receive data from the ViewModel. How can I send data from onActivityResult to the ViewModel class and then update my list? If…
Infernal
  • 202
  • 3
  • 13
3
votes
1 answer

How to use multiple viewmodels in single fragment in Android?

Let's say I have DashboadFragment which has its own ViewModel named DashboadViewModel. I have created separate layout for AutoCompleteTextView which is included in fragment_dashboard.xml file. I have created separate ViewModel for…
3
votes
2 answers

Looking for ideas to implement SearchView in Android in a Single Activity App approach

Looking for ideas to implement SearchView in Android. I am using Single Activity Approach in my app. I was following this doc : https://developer.android.com/guide/topics/search/search-dialog But this adds the overhead of adding new…
3
votes
1 answer

How to manipulate properties of Livedata list

Say like LiveData is received from remote and few of the Item's properties are calculated in the device based on some conditions. What would be the best practices to do so. Please suggest. Say e.g., Item class as below: class Item{ …
Faisal
  • 1,332
  • 2
  • 13
  • 29
3
votes
1 answer

android - type mismatch in view model by using MutableLiveData

I'm using mvvm architecture in my app ,this is my code : class ProductRepository : BaseRepository() { private val mutableLiveData = MutableLiveData() fun getProducts(catId: String): MutableLiveData { if…
Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58
3
votes
0 answers

Pass data to ViewModel while using Dagger

MVVM + Dagger2 I'm very new to Dagger. I've gone through many sample project and created this. What i want to know is using the below code, how to send data to specific ViewModels. I know how to do it by creating specific ViewModelProvider.Factory.…
Shahal
  • 1,008
  • 1
  • 11
  • 29
3
votes
2 answers

Is it possible to pass a String parameter to viewModel from Android xml

Is it possible to pass a String parameter on a button click of XML file to the methods of the view model file as like below android:onClick="@{v -> viewModel.postFeedRequest(@string/show_details)}" I tried like above i am getting binding…
Rakesh
  • 14,997
  • 13
  • 42
  • 62
3
votes
2 answers

MVVM injecting Activity string resource reader

So, everyone knows that passing a Context reference (which is not Application) to ViewModel is a bad thing. In my case, there are some items to be ordered alphabetically using an android string resource representation (so, to read it I need an…
DoruAdryan
  • 1,314
  • 3
  • 20
  • 35
3
votes
2 answers

When submitting a new list to RecyclerView ListAdapter the diff check always returns true for areContentsTheSame()

I am using an MVVM architechture to build a simple ordering app. I am using a RecyclerView in my ProductsFragment to list all the products that can be ordered. I am also using LiveData in my ViewModel and observable in my Fragment to check for any…
3
votes
1 answer

Android Architecture Components

I am using MVVM android architecture for my application. I want to implement click event, so, do we need to use data binding architecture components or we can just use activity for handling the click event and validating the user inputs? What's the…
3
votes
1 answer

Need help to refactor FIrebase phone authentication into MVVM architecture

I am unable to figure out how to handle login Result from FirebaseLoginRepository class back to LoginViewModel after authentication like whether it's successful or not ,should i use a callback listener as we do in MVP pattern ? Pardon me in case of…
3
votes
1 answer

Where to create the repository object in android apps?

How and where do you create the repository object in your android apps? Do you implement your repository as a singletone? Is it a static class? I am trying to use the single activity approach: Apparently I wanna use the same repository in each…
3
votes
2 answers

lateinit property has not been initialized with dagger2

I am new to Android and I am trying to create an app with Dagger2 and MVVM pattern and kotlin, but I cannot make it run. My application class code. class PruebaDaggerApp: Application(), HasActivityInjector, HasSupportFragmentInjector…
Otto Cheley
  • 552
  • 9
  • 20
3
votes
1 answer

Using databinding to highlight selected recyclerview row

I'm trying to highlight a row of my recyclerview when a user clicks on it. Recyclerview row layout:
3
votes
1 answer

It is ok to call observeForever() on Livedata returned by Transformations.map() inside ViewModel?

I tried to use LiveData Transformations.map() to check the result and update the UI. But Transformations.map() callback not triggered without an observer. So is it good way to call observeForever {} on livedata returned by Tranformations.map? And…