-2

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

two
  • 15
  • 2

1 Answers1

0

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

41 72 6c
  • 1,600
  • 5
  • 19
  • 30
two
  • 15
  • 2