'Reuse FragmentContainerView passing a tag/Bundle/Interface or Boolean in a Jetpack Navigation project
I have a whatever RecyclerView inside MyListFragment and I call this Fragment from a MotherFragmentOne just adding in xml:
<androidx.fragment.app.FragmentContainerView android:id="@+id/fragment_myList" android:name="com.example.MyListFragment"
Now I need to reuse the same Recyclerview inside MotherFragmentTwo except for the case that clicking on the item inside the recyclerview is going to navigate to another view:
MotherFragmentOne ->onClick of an item bring me to DisneylandFragment
MotherFragmentTwo ->onClick of an item bring me to MarvelFragment
How can I achieve this? I want to say that MotherFragmentOne and MotherFragmentTwo are inside a navhost, using the Jetpack Navigation so I am wondering how can I pass a boolean, a bundle, an interface or whatever so that when the MList initializes the Adapter I can handle the two click.
Of course a terrible solution is to duplicate code but this is against the SOLID principles:
<androidx.fragment.app.FragmentContainerView android:id="@+id/fragment_myList" android:name="com.example.AHAH_I_AmUsingAnotherFragmentAndDoNotCare"
but I do not know how to not repeat my self and passing a value to handle the logic in MyListFragment on the two different use cases
EDIT I was able to call it programmatically and passing a bundle although it looks to me as hack maybe there is a navigation jetpack way to achieve that
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
