Skip to content

Instantly share code, notes, and snippets.

@maiconhellmann
Created September 1, 2019 11:52
Show Gist options
  • Save maiconhellmann/a923288550c1f30596512c22fb7a7274 to your computer and use it in GitHub Desktop.
Save maiconhellmann/a923288550c1f30596512c22fb7a7274 to your computer and use it in GitHub Desktop.
A simple recyclerView adapter/viewHolder
class CurrencyAdapter: RecyclerView.Adapter<CurrencyAdapter.ViewHolder>() {
var data: List<YourModelName> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(parent)
}
override fun getItemCount() = data.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(data[position])
}
inner class ViewHolder(parent: ViewGroup): RecyclerView.ViewHolder(parent.inflate(R.layout.item_layoutname)) {
fun bind(model: YourModelName)= with(itemView) {
//TODO
itemView
}
}
}
private fun ViewGroup.inflate(layout: Int): View {
return LayoutInflater.from(context).inflate(layout, this, false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment