Skip to content

Instantly share code, notes, and snippets.

@alfianyusufabdullah
Created May 24, 2019 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfianyusufabdullah/1683e66b8cee24745e0891bd1569d0e6 to your computer and use it in GitHub Desktop.
Save alfianyusufabdullah/1683e66b8cee24745e0891bd1569d0e6 to your computer and use it in GitHub Desktop.
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