Skip to content

Instantly share code, notes, and snippets.

@henriquehorbovyi
Last active December 19, 2018 02:55
Show Gist options
  • Save henriquehorbovyi/fd29d36e10d5dfc69c78ca38a7158b07 to your computer and use it in GitHub Desktop.
Save henriquehorbovyi/fd29d36e10d5dfc69c78ca38a7158b07 to your computer and use it in GitHub Desktop.
class TestListAdapter(private val context: Context) : RecyclerView.Adapter<TestListAdapter.ViewHolder>(){
private val data: MutableList<TestModel> = mutableListOf()
override fun getItemCount(): Int = data.count()
override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.list_Test, parent ,false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bindItem(data[position])
}
/* Method to update adapter data */
private fun update(d: List<TestModel>){
data.addAll(d)
notifyDataSetChanged()
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindItem(test: TestModel){
//var name: TextView = itemView.findViewById<TextView>(R.id.CatName)
//name.text = test.name
// you don't need to make findViewById
itemView.CatName.text = test.name // <- just do this
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment