i am using navigation, fragments, & recyclervi...
# android
z
i am using navigation, fragments, & recyclerviews
i
If you're using Navigation, you'd just use
view.findNavController().navigate(R.id.your_id)
- you never reference fragments by class name
z
@Ian Lake - i want each item in the recyclerview to navigate to its respective location. i guess the only problem i have with this is "view.button.setOnClickListener". what do i replace the button with?
Copy code
override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    // Inflate the layout for this fragment
    val view: View = inflater.inflate(R.layout.fragment_title, container, false)

    view.Btn.setOnClickListener { view: View ->
        view.findNavController().navigate(R.id.action_titleFragment_to_secondFragment)
    }
    return view
}
i
You set click listeners for RecyclerView in your adapter / ViewHolder. There you know what position and therefore what data you have for that row
z
ahhhhhhh
ian you are a life saver
let me try that
Copy code
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    val currentItem = homeFeed.data[position]
    holder.itemView.setOnClickListener(
    Navigation.createNavigateOnClickListener(R.id.action_secondFragment_to_ListFragment)
    )
@Ian Lake something like this?
i
Something like that, yeah. I assume your
currentItem
might have fields you want to pass as arguments to your call or would be where you'd store the
R.id
for the destination that row is associated with