Issue
I am converting project from many activities to one activity with many fragments and using navigation component to do so. There is one activity that accepts multiple lists of about 10 different lists of all different types. When creating the arguments for the fragment to pass into it how do I do this for an arg that can be any type list?
Here is how I grab it from activity in onCreate.
intent.getParcelableArrayListExtra<Parcelable>("listItems")
I know I will have to do something like this when I send it to the fragment
val bundle = bundleOf("ListItems" to (list as ArrayList<out Parcelable>))
findNavController().navigate(R.id.action, bundle)
Solution
So I ended up doing this. To me its a bit hacky but it works consistently as long as the lists are not gigantic.
binding.button.setOnClickListener {
val bundle = bundleOf("ListItems" to (list as ArrayList<out Parcelable>))
findNavController().navigate(R.id.action_home_to_see_list, bundle)
}
And then in the fragment I am passing this data to I just do this
val list = arguments?.getParcelableArrayList<ListItems>("ListItems")?.toList()
Not happy with this solution as it feels hacky to me but it works
Answered By - JPM
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.