Created
August 3, 2018 13:03
-
-
Save kozmi55/43ea24a8cb338eb20c80c32078ab9a91 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 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