I want to navigate from HomeFragment to DetailFragment in RecyclerView item click I am calling DetailFragment and it is not working ,I see it enters onClickListener but it doesn't go further and it doesn't call DetailFragment
viewBinding.assetImage.setOnClickListener {
val bundle = bundleOf("owner" to "TestUser")
Navigation.createNavigateOnClickListener(R.id.detail_screen,bundle)
}
<fragment
android:id="@+id/home_screen"
android:name="HomeFragment"
android:label="@string/title_home"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_home_screen_to_detailFragment"
app:destination="@id/detail_screen" />
</fragment>
<fragment
android:id="@+id/detail_screen"
android:name="DetailFragment"
android:label="DetailFragment"
tools:layout="@layout/fragment_detail">
<argument
android:name="owner"
app:argType="string" />
</fragment>
Below is solution for you,
val bundle = Bundle()
bundle.putString("owner", "TestUser")
if (it.findNavController().currentDestination?.id == R.id.home_screen) {
it.findNavController().navigate(R.id.action_home_screen_to_detailFragment, bundle)
}