Skip to content

Instantly share code, notes, and snippets.

@wajahatkarim3
Created June 20, 2022 14:38
Show Gist options
  • Save wajahatkarim3/532b16d77aa86641c282bade64675f20 to your computer and use it in GitHub Desktop.
Save wajahatkarim3/532b16d77aa86641c282bade64675f20 to your computer and use it in GitHub Desktop.
class UserListAdapter() : RecyclerView.Adapter<UserListAdapter.ViewHolder>() {
private var items= emptyList<User>()
inner class ViewHolder(val binding: UserListItemLayoutBinding) :
RecyclerView.ViewHolder(binding.root) { }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
UserListItemLayoutBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.binding.apply {
this.image.setImageResource(items[position].image)
this.name.text=items[position].name.toString()
this.achivements.text = items[position].achievement.toString()
}
}
override fun getItemCount(): Int {
return items.size
}
@SuppressLint("NotifyDataSetChanged")
fun setUsersListData(itemsList:List<User>){
this.items=itemsList
this.notifyDataSetChanged()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment