Created
June 18, 2018 05:41
-
-
Save gsanthosh91/4f68942758a59864ae69f1edababd990 to your computer and use it in GitHub Desktop.
Live template for Recyclerview Adapter in Kotlin
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.support.v7.widget.RecyclerView | |
| import android.view.LayoutInflater | |
| import android.view.View | |
| import android.view.ViewGroup | |
| class ${NAME}(private val list: List<${LIST_MODEL}>) : RecyclerView.Adapter<${NAME}.CustomViewHolder>() { | |
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder { | |
| val rowView = LayoutInflater.from(parent.context).inflate(R.layout.${item_layout}, parent, false) | |
| return CustomViewHolder(rowView) | |
| } | |
| override fun getItemCount(): Int { | |
| return list.count() | |
| } | |
| override fun onBindViewHolder(holder: CustomViewHolder, position: Int) { | |
| val item = list.get(position) | |
| //holder.rowView.name.text = item.name | |
| holder.item = item | |
| } | |
| class CustomViewHolder(val rowView: View, var item: ${LIST_MODEL}? = null) : RecyclerView.ViewHolder(rowView) { | |
| init { | |
| rowView.setOnClickListener { | |
| //println(item) | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HOW TO USE
Move this file into template directory