I have a feed fragment that its main element is a RecyclerView of posts.
I am managing the recycler with Lisa Wray's Groupie library https://github.com/lisawray/groupie
Now in my navigation graph I have an action connecting the feed fragment to the another fragment, and I try to call this action with an on click listener I create in the bind function of the adapter.
val action=FeedFragmentDirections.actionDestinationFeedToDestinationAddToBucket(image.id)
findNavController().navigate(action)
I keep getting an error saying navigation destination XXXXX is unknown to this NavController
I've tried adding a few things before the findNavController()
, like viewHolder.itemView
or viewHolder.root
but nothing works.
When I use viewHolder.itemView.rootView
I get this error instead View DecorView@a190adf[MainActivity] does not have a NavController set
I don't know what DecorView is.
Any ideas how I can implement my oncick listeners properly?
Using itemView seems to work too as that's what I have on my code:
class RecyclerSettingsItem(
private val activity: MainActivity,
private val settingItem: String
) : Item<GroupieViewHolder>() {
override fun bind(viewHolder: GroupieViewHolder, position: Int) {
var navController: NavController? = null
viewHolder.apply {
with(viewHolder.itemView) {
tvTitle.text = settingItem
itemView.setOnClickListener {
navController = Navigation.findNavController(itemView)
navController!!.navigate(R.id.action_settingsFragment_to_contactTracingFragment)
}
}
}
}
override fun getLayout() = R.layout.rv_settings_item_row
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With