Created
August 3, 2018 11:42
-
-
Save kozmi55/6b93b97506af99f1cbd7f5fdab6166a6 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>() { | |
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