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

66
October 20, 2021, at 05:00 AM

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

Answer 1

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

Answer 2

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

READ ALSO
login failed with php oop with ajax

login failed with php oop with ajax

I have done login page using php oops with ajax for signin buttonif(isset($result["username"])!="") Its return wrong details in Json type

40
Getting Empty File with AWS Lambda and ALB

Getting Empty File with AWS Lambda and ALB

I have used the Npm package, http-proxy-middleware

58
Trying to multiply and make another row in Pandas Dataframe

Trying to multiply and make another row in Pandas Dataframe

How do I make another row called 'Sum'), which contains the sum of for each order line (quantity, multiplied by price)in Pandas

59
Append method to add text to body not working [duplicate]

Append method to add text to body not working [duplicate]

This is such a simple command and I am loading jQuery beforehandOther jQuery on the page is working as well

68