Last active
September 26, 2018 06:58
-
-
Save faruktoptas/0441ad0a198eb81a209c0eed1ef20151 to your computer and use it in GitHub Desktop.
Simple RecyclerView Adapter
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 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