Last active
December 19, 2018 02:55
-
-
Save henriquehorbovyi/fd29d36e10d5dfc69c78ca38a7158b07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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