Home > Net >  what are the correct methods to Observe MutableLiveData <ArrayList<Objects>> ? Android
what are the correct methods to Observe MutableLiveData <ArrayList<Objects>> ? Android

Time:10-20

I am working on a RecyclerView that retrieves some of the data from an Object, every time a new object is created that object will be added into SQLiteDatabase and then to my ViewModel MutableLiveData<ArrayList>. so my question is how can i set a method in my fragment that observes the changed array list of objects so that my recyclerview will automatically updated.

for MutableLiveData i have used the below method to Observe but its not working for ArrayList of objects in my case.

//this is an example

ViewModel.getChangedData().observe(requireActivity(),item->{
            textview.setText(item);

please help, i am a beginner in this. i am using Java.

thanks in advance

CodePudding user response:

I also remember setting up the Recycler View. The step-by-step documentation helped me a lot. I advise you to follow the instructions and build a test project. My project to used SQLite LiveData RecyclerView https://play.google.com/store/apps/details?id=com.mardaunt.telesupp&hl=ru&gl=US

CodePudding user response:

Guys i have figured it out.. i needed to do this

candidates = myViewModel.getCandidates().getValue();
instead i was doing,  candidates = myViewModel.getCandidates();

candidates is ArrayList in this case

  • Related