enter image description hereI have almost 250 patent item which i want to show in a parent recyclerview. After item click of parent recyclerview it will show over hundreds of data under each parent item in another recycler view. How can i do it like this picture.
0
votes
1 Answers
0
votes
I would do it this way. Create an interface:
interface AdapterContract{
fun onListItemClick(id: String) //whatever the parameter is
}
When you instantiate the Adapter in your Fragment1
, you can implement this interface:
class Fragment1 : Fragment(), AdapterContract{
...
//when instantiating the adapter:
private val adapter: MyAdapter by lazy{
MyAdapter(this //for the interface)
}
//override the method of Adapter contract
}
Your adapters constructor should look like this: MyAdapter(adapterContract: AdapterContract) : ListAdapter<MyAdapter.MyViewHolder>(Diff_Util_SOME_OBJECT)
Than in the adapters ViewHolder:
itemHolder?.setOnClickListener{
adapterContract.onListItemClick(someId)
}
Now in your override method in Fragment1
:
override method onListItemClick(id: String){
//pass this id to the next opening fragment (like Bundles or navargs)
//init `Fragment2` which is going to have all items, that belong to `Fragment1` selected item
}
Load the data :)
I hope you are using a database or something. Should work with hard coded data structures as well, but just to be safe :).