I am using Android Navigation Component and following the MVVM pattern(with Repository and Room). I am making a notes app where I have a Main Activity and two fragments. Show Notes Fragment and Add/Update Notes fragment. I ran into a problem when passing the data while navigating to second fragment. I have a navGraph where I have mentioned two actions i.e action_first_fragment_to_second_fragment and back to the first fragment. I want a functionality where if I click on the FAB icon in the first fragment it would take me to the second fragment to add new notes and navigate through the action mentioned above . Also, when I click on the note items in the recyclerview in the first fragment, it should pass the existing data of that note to the second fragment and populate the fields accordingly.
The argument type I have given tot he Second Fragment in the navGraph is the Notes Entity, which I have made as parcelable.
The problem I am facing is that :
- when I mention the argument as nullable and handle the FAB click in the first fragment, I can successfully pass "null" as the argument BUT when I handle the item click in the recycler view items in the adapter class, I cannot pass the notesEntity. I want to use the same action but pass "nothing" when handling the FAB click BUT when handling the recycler view item click I want to pass the notes entity using the same action. How Can I Do that... please tell ....
I am Using JAVA and also uploading an Image for better understanding. please see this image Please tell.