Skip to content
Advertisement

How to implement “favourite” button feature (like favourite recipe/food) and display on another list in another fragment

I want to have a feature that when the user clicked the button on a certain row, it will add the row to another list which is called favorite list. Currently i have created database that also include favourite status. I already tried to start with creating a button that when its clicked it will change the fav status. Im still new on android studio, just learnt for half a month. So go easy on me. I am currently stuck on this error:

JavaScript

Recipe.java

JavaScript

DatabaseHandler.java

JavaScript

RecyclerViewAdapter.java

JavaScript

recipeRow.xml

JavaScript

Advertisement

Answer

The following error can occur when you try to use object which is not initialised before using it. means it’s in null state, as you can see your db object in RecyclerViewAdapter is not initialised.

to solve this just initialised the object before using it or check if it’s not null.

in you case just do as

RecyclerViewAdapter.java

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement