Questions regarding applying a Model-View-ViewModel in android application
Questions tagged [android-mvvm]
773 questions
2
votes
0 answers
How to add a datepicker through ViewModel class in MVVM android
I have a edittext and when I click tthat, I want to show a DatePicker,
This is what I tried but I get an error
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
class…

BRDroid
- 3,920
- 8
- 65
- 143
2
votes
2 answers
Android Repository Pattern convert room to domain model
I am desperately looking for a possability to convert a room model to a domain model to enable offline functionality to my app. I have successfully implemented this pattern as described in this codelab:…

Max Mustermann
- 61
- 1
- 7
2
votes
1 answer
MVVM: updating viewpager2's container view from inner fragments
I'm in trouble :D I starting to use mvvm and LiveData, and I want to do it in better way.
I will try to explain you my doubt with a simple example :
I have a container fragment "Exams" containing a ViewPager2 that contain some fragments…

aeroxr1
- 1,014
- 1
- 14
- 36
2
votes
2 answers
Good practice for communicate between viewModel and fragment
I'm implementing the viewModel and for communicate between the viewModel and fragment I'm doing this :
public class SplashViewModel extends AndroidViewModel {
private LiveData actions;
public SplashViewModel(@NonNull Application…

Vodet
- 1,491
- 1
- 18
- 36
2
votes
1 answer
Why does ViewModelProvider creates new instance of view model on screen rotation?
Im trying to implement Paging but every time i rotate a screen constructor of view model gets called, thus triggering loadInitial to fetch new data from network in my DataSource class.Help appreciated
// ViewModel
def lifecycle_version =…

Nikola Srdoč
- 311
- 4
- 14
2
votes
1 answer
Is it okay to store properties in a Repository for reuse?
I am making an app with some friends, and we have decided to go with the MVVM pattern. However, their understanding of the pattern differs from mine.
My question is: If we have a data that we would like to reuse in other views, can we store them as…

redouane
- 127
- 1
- 9
2
votes
1 answer
Changes are not observable by viewmodel
I have created an app which is relied on my local server which fetch profile image and information about user..Code works fine without any problem but when I change my data in the local server (for example profile picture )the updated profile is…

Hrishi Bargal
- 19
- 5
2
votes
1 answer
How to Implement ViewModel Factory in Android
I am implementing Room database with ViewModel. Everything works well. But the requirement is I want to provide some dependency to ViewModel using AndroidViewModelFactory. I am able to create ViewModelFactory class which implements…

Satyam Gondhale
- 1,415
- 1
- 16
- 43
2
votes
1 answer
For which other situations is ViewModel class useful for , (apart from screen rotation) when dealing with data?
I am beginner in Android studio and I started learning the different Architecture components within the Android Jetpack. When dealing with data, I realized that in almost every tutorial or documentation the ViewModel class is used. It is always…

Berni
- 551
- 10
- 17
2
votes
2 answers
How to bind viewmodel to a gridView in android?
I have a gridView in my activity with a custom adapter class, I cannot figure out how to bindview model to my activity's gridView.
Here is my gridview adapter:
class ImageAdapter constructor(val mContext: Context, private val resource_layout: Int,…

SuvodipMondal
- 87
- 1
- 8
2
votes
2 answers
How to reuse a Fragment and ViewModel with different Repository Implementation injected by Dagger2.2
I'm kinda new to Android development and I have been stuck finding a way to do this pattern using some android libraries like Dagger2, Fragments, and ViewModel.
I hope some of you can help me with this or stating what's the common way to do this on…

MarMass
- 5,755
- 1
- 18
- 15
2
votes
1 answer
Best practice using RecyclerView, ListAdapter and ViewModel for saving checked status
I am using RecyclerView with ListAdapter which using DiffUtil internally to show the data. Of course, all the data was provided by ViewModel via LiveData.
Now each item view has a CheckBox, meanwhile I implemented drag selection function by adding…

Chenhe
- 924
- 8
- 19
2
votes
4 answers
DiffUtil not updating ListAdapter after updating ArrayList contents
I am trying to update ArrayList which is inside in MutableLiveData.
whenever I change the content in ArrayList, ListAdapter is not updating.
ViewModel
private var _tileNumberList:MutableLiveData> = MutableLiveData()
var…

iamkdblue
- 3,448
- 2
- 25
- 43
2
votes
0 answers
MVVM average Fragment inflation time and how to improve performance
I have recently re-written an app for a client. The original was made up of about 20 activities and has now changed to a single activity and about 7 fragments with ViewModels for each fragment. Its a pretty small app in general so I simply swap…

DevinM
- 1,112
- 1
- 12
- 29
2
votes
1 answer
how to understand the dependency on mvvm?
I know that the mvvm model is seperated to 3 elementes, model viewmodel view. but studying mvvm with my application dev, I thought there is really no dependency? here is my code on MainActivity.
Do I misunderstand the mvvm or misuse? I think the…

jakchang
- 402
- 5
- 13