Skip to content

Instantly share code, notes, and snippets.

Created June 3, 2021 11:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
class PhonesHomeAdapter(
private val phonesHomeList: List<Phone>?,
private val listener: (String) -> Unit
) : RecyclerView.Adapter<PhonesHomeAdapter.ViewHolder>() {
private lateinit var binding: ItemPhoneHomeBinding
class ViewHolder(private val binding: ItemPhoneHomeBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(phone: Phone?, listener: (String) -> Unit) {
binding.apply {
name.text = phone?.name
root.setOnClickListener {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
binding = ItemPhoneHomeBinding.inflate(
LayoutInflater.from(parent.context), parent, false
return ViewHolder(binding)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(phonesHomeList?.get(position), listener)
override fun getItemCount() = phonesHomeList!!.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment