I'm new at navigation graph and I have a simple movie application that contains a BottomNavigationView
with 2 tabs or 2 icons , the first icon or first tab contains 2 Fragments
the first one is FeedFragment
and I navigate from it to DetailsFragment
and I put these 2 Fragment
in nested graph
. The second tab for FavoritFragment
.
Below my code in nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_nav"
app:startDestination="@id/homeNavigation">
<fragment
android:id="@+id/favoritesFragment"
android:name="com.tito.movieapps.ui.fragments.FavoritesFragment"
android:label="@string/favorites"
tools:layout="@layout/fragment_favorites" >
<action
android:id="@+id/action_favoritesFragment_to_homeNavigation"
app:destination="@id/detailsFragment" />
</fragment>
<navigation
android:id="@+id/homeNavigation"
android:label="Home nested graph"
app:startDestination="@id/feedFragment">
<fragment
android:id="@+id/feedFragment"
android:name="com.tito.movieapps.ui.fragments.FeedFragment"
android:label="@string/feed_page"
tools:layout="@layout/fragment_feed">
<action
android:id="@+id/action_feedFragment_to_detailsFragment"
app:destination="@id/detailsFragment" />
</fragment>
<fragment
android:id="@+id/detailsFragment"
android:name="com.tito.movieapps.ui.fragments.DetailsFragment"
android:label="Details"
tools:layout="@layout/fragment_details">
<argument
android:name="movieItem"
app:argType="com.tito.domain.entites.MovieModelItem" />
</fragment>
</navigation>
</navigation>
I can navigate from FeedFragment
to DetailsFragment
and I pass a Parcelable
object .
I want to navigate from FavoriteFragment
to DetailsFragment
(in the nested navigationGraph
) and when I write the below code in FavoriteFragment
lifecycleScope.launchWhenStarted {
detailsViewModel.getSavedMovie().collectLatest { movies->
if(movies.isNotEmpty()) {
favoritesAdapter = FavoritesAdapter(object : FavoritesAdapter.OnItemClick{
override fun onItemClick(movieModelItem: MovieModelItem) {
val id = FavoritesFragmentDirections.actionFavoritesFragmentToHomeNavigation(movieModelItem)
findNavController().navigate(id)
}
})
binding.movieRec.adapter = favoritesAdapter
favoritesAdapter.differ.submitList(movies)
}else{
Toast.makeText(requireActivity(),"No data",Toast.LENGTH_LONG).show()
}
}
}
And run the app , I can't run it I get the below error
e: D:\MovieApps\app\src\main\java\com\tito\movieapps\ui\fragments\FavoritesFragment.kt: (48, 105): Too many arguments for public final fun actionFavoritesFragmentToHomeNavigation(): NavDirections defined in com.tito.movieapps.ui.fragments.FavoritesFragmentDirections.Companion
I can't fix this error so please help me
nav_graph.xml
. And when I make an action from Favorite to the Home graph , it navigate to the Home no the Details screen – Haricot