Slide 19
Slide 19 text
ShoppingListAdapter.kt
class ShoppingListAdapter(private val data: List):
RecyclerView.Adapter() {
class ViewHolder(view: View): RecyclerView.ViewHolder(view){}
override fun getItemCount(): Int = data.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
// ...
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int)
}
ShoppingListFragment.kt
val adapter = ShoppingListAdapter(data)
val recyclerView: RecyclerView = findViewById(R.id.recycler_view)
recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false)