Skip to content

Instantly share code, notes, and snippets.

@faruktoptas
Last active September 26, 2018 06:58
Show Gist options
  • Save faruktoptas/0441ad0a198eb81a209c0eed1ef20151 to your computer and use it in GitHub Desktop.
Save faruktoptas/0441ad0a198eb81a209c0eed1ef20151 to your computer and use it in GitHub Desktop.
Simple RecyclerView Adapter
class MyRecyclerViewAdapter(private val list: List<MyModel>) : RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.row_recycler, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val myModel = list[position]
holder.title.text = myModel.title
}
override fun getItemCount(): Int {
return list.size
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val title: TextView = view.findViewById(R.id.tvMain) as TextView
}
}
data class MyModel(val title: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment