Created
August 24, 2022 06:58
-
-
Save mym0404/b50ef477dbbce434786f6eb7915242be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data class MyData(val id: Int) | |
| class MyAdapter : RecyclerView.Adapter<MyAdapter.Holder>() { | |
| private var items: List<MyData> = listOf() | |
| fun submitList(items: List<MyData>) { | |
| this.items = items | |
| notifyDataSetChanged() | |
| } | |
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { | |
| val inflater = LayoutInflater.from(parent.context) | |
| val binding = ItemMyBinding.inflate(inflater, parent, false) | |
| return Holder(binding) | |
| } | |
| override fun getItemCount() = items.size | |
| override fun onBindViewHolder(holder: Holder, position: Int) = holder.bind(items[position]) | |
| class Holder(private val binding: ItemMyBinding) : RecyclerView.ViewHolder(binding.root) { | |
| fun bind(item: MyData) { | |
| // do something | |
| // binding.textView.text = item.id.toString() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment