Skip to content

Instantly share code, notes, and snippets.

@Ahmad-Hamwi
Created September 24, 2021 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahmad-Hamwi/200c5ecc5dbd23ac823120aaf3ecd02d to your computer and use it in GitHub Desktop.
Save Ahmad-Hamwi/200c5ecc5dbd23ac823120aaf3ecd02d to your computer and use it in GitHub Desktop.
class CategoriesAdapter(
private val context: Context,
private val listOfCategories: List<Category>
) : RecyclerView.Adapter<CategoriesAdapter.CategoryViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryViewHolder {
return CategoryViewHolder(
LayoutInflater.from(context).inflate(R.layout.item_category, parent, false)
)
}
override fun onBindViewHolder(holder: CategoryViewHolder, position: Int) {
holder.bind(listOfCategories[position])
}
override fun getItemCount(): Int {
return listOfCategories.size
}
class CategoryViewHolder(
private val view: View
) : RecyclerView.ViewHolder(view) {
fun bind(category: Category) {
view.findViewById<TextView>(R.id.categoryName).text = category.name
view.findViewById<RecyclerView>(R.id.recyclerView).adapter =
ItemsAdapter(view.context, category.listOfItems)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment