Skip to content

Instantly share code, notes, and snippets.

@IkhwanSI13
Created April 23, 2020 12:28
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 IkhwanSI13/059ade2bc904b1e06526e92d2fd7264f to your computer and use it in GitHub Desktop.
Save IkhwanSI13/059ade2bc904b1e06526e92d2fd7264f to your computer and use it in GitHub Desktop.
Live template for RecyclerView
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.extensions.LayoutContainer
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.${LAYOUT_NAME}.*
class ${NAME}(private val context: Context,
private val items: MutableList<${TYPE_LIST}>,
private val listenerItemClick: (${TYPE_LIST}) -> Unit) :
RecyclerView.Adapter<${NAME}.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
ViewHolder(LayoutInflater.from(context).inflate(R.layout.${LAYOUT_NAME}, parent, false))
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bindItem(position, items, listenerItemClick, context)
}
override fun getItemCount(): Int = items.size
class ViewHolder(override val containerView: View) : RecyclerView.ViewHolder(containerView),
LayoutContainer {
fun bindItem(position: Int, list: MutableList<${TYPE_LIST}>, listenerItemClick: (${TYPE_LIST}) -> Unit,
context: Context) {
val data = list.get(position)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment