Created
April 23, 2020 12:28
-
-
Save IkhwanSI13/059ade2bc904b1e06526e92d2fd7264f to your computer and use it in GitHub Desktop.
Live template for RecyclerView
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
#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