Created
September 24, 2021 08:52
-
-
Save Ahmad-Hamwi/2846f58b583209ca94679e436fc78241 to your computer and use it in GitHub Desktop.
This file contains 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
class ItemsAdapter( | |
private val context: Context, | |
private var items: List<Item> | |
) : | |
RecyclerView.Adapter<ItemsAdapter.ItemViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { | |
return ItemViewHolder( | |
LayoutInflater.from(context).inflate(R.layout.item_item, parent, false) | |
) | |
} | |
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { | |
holder.bind(items[position]) | |
} | |
override fun getItemCount(): Int { | |
return items.size | |
} | |
class ItemViewHolder(private val view: View) : | |
RecyclerView.ViewHolder(view) { | |
fun bind(item: Item) { | |
view.findViewById<TextView>(R.id.textViewContent).text = item.content | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment