Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MainAdapter(private val teams: List<Team>)
: RecyclerView.Adapter<TeamViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TeamViewHolder {
return TeamViewHolder(TeamUI().createView(AnkoContext.create(parent.context, parent)))
}
override fun onBindViewHolder(holder: TeamViewHolder, position: Int) {
holder.bindItem(teams[position])
}
override fun getItemCount(): Int = teams.size
}
class TeamUI : AnkoComponent<ViewGroup> {
override fun createView(ui: AnkoContext<ViewGroup>): View {
return with(ui) {
linearLayout {
lparams(width = matchParent, height = wrapContent)
padding = dip(16)
orientation = LinearLayout.HORIZONTAL
imageView {
id = team_badge
}.lparams{
height = dip(50)
width = dip(50)
}
textView {
id = team_name
textSize = 16f
}.lparams{
margin = dip(15)
}
}
}
}
}
class TeamViewHolder(view: View) : RecyclerView.ViewHolder(view){
private val teamBadge: ImageView = view.find(team_badge)
private val teamName: TextView = view.find(team_name)
fun bindItem(teams: Team) {
Picasso.get().load(teams.teamBadge).into(teamBadge)
teamName.text = teams.teamName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.