Skip to content

Instantly share code, notes, and snippets.

@kishansinhparmar
Created July 19, 2019 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishansinhparmar/f5a263e063af303c59c9a933c9290d62 to your computer and use it in GitHub Desktop.
Save kishansinhparmar/f5a263e063af303c59c9a933c9290d62 to your computer and use it in GitHub Desktop.
class $CLASS_NAME$Adapter(private var list: MutableList<$DT$>) :
RecyclerView.Adapter<$CLASS_NAME$Adapter.$CLASS_NAME$ViewHolder>() {
override fun getItemCount() = list.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): $CLASS_NAME$ViewHolder {
return $CLASS_NAME$ViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.$LAYOUT_NAME$,
parent,
false
)
)
}
override fun onBindViewHolder(holder: $CLASS_NAME$ViewHolder, position: Int) {
list[holder.adapterPosition]
holder.onBind(holder.adapterPosition)
}
class $CLASS_NAME$ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
view.iChooseLan_imCountry
fun onBind(position: Int){
itemView.setOnClickListener {
}
}
}
fun insert(newItem: $DT$) {
list.add(newItem)
notifyItemInserted(list.size + 1)
}
fun remove(position: Int) {
list.removeAt(position)
notifyItemRemoved(position)
}
fun removeAll() {
list.removeAll { true }
notifyDataSetChanged()
}
fun update(position: Int, updated: $DT$) {
list[position] = updated
notifyItemChanged(position)
}
fun getMyList(): MutableList<$DT$> {
return list
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment