Skip to content

Instantly share code, notes, and snippets.

@kozmi55
Created August 3, 2018 13:03
Show Gist options
  • Save kozmi55/43ea24a8cb338eb20c80c32078ab9a91 to your computer and use it in GitHub Desktop.
Save kozmi55/43ea24a8cb338eb20c80c32078ab9a91 to your computer and use it in GitHub Desktop.
class UserAdapter : RecyclerView.Adapter<UserAdapter.UserHolder>(), BindableAdapter<List<Long>> {
override fun setData(items: List<Long>) {
userIds = items
notifyDataSetChanged()
}
var userIds = emptyList<Long>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserHolder {
val inflater = LayoutInflater.from(parent.context)
return UserHolder(inflater.inflate(R.layout.list_item, parent, false))
}
override fun getItemCount() = userIds.size
override fun onBindViewHolder(holder: UserHolder, position: Int) {
holder.bind(userIds[position])
}
class UserHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(userId: Long) {
itemView.userText.text = "User id: $userId"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment