Created
September 1, 2019 11:52
-
-
Save maiconhellmann/a923288550c1f30596512c22fb7a7274 to your computer and use it in GitHub Desktop.
A simple recyclerView adapter/viewHolder
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 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