Created
November 15, 2016 13:18
-
-
Save sembozdemir/05ea3c0967b942d3286810d48d57d4b9 to your computer and use it in GitHub Desktop.
ToDoKotlin - ToDoListAdapter.kt
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 TodoListAdapter(val arrayList: ArrayList<String> = ArrayList<String>()) | |
: RecyclerView.Adapter<TodoListAdapter.ViewHolder>() { | |
override fun getItemCount(): Int = arrayList.size | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val itemView = TextView(parent.context).apply { | |
padding = dip(16) | |
} | |
return ViewHolder(itemView) | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.textView.text = arrayList[position] | |
} | |
fun add(text: String) { | |
arrayList.add(0, text) | |
notifyItemInserted(0) | |
} | |
class ViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment