Created
June 20, 2022 14:38
-
-
Save wajahatkarim3/532b16d77aa86641c282bade64675f20 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
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