Skip to content

Instantly share code, notes, and snippets.

@sjthn
Last active May 7, 2018 12:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjthn/198cac1f6ae0d29352ca181fac0f5318 to your computer and use it in GitHub Desktop.
Save sjthn/198cac1f6ae0d29352ca181fac0f5318 to your computer and use it in GitHub Desktop.
Kotlin template for RecyclerView Adapter in Android Studio
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
#end
#parse("File Header.java")
class ${NAME}(private var items: MutableList<${ITEM_TYPE}>): RecyclerView.Adapter<${VIEWHOLDER}>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ${VIEWHOLDER} {
// TODO: Return ${VIEWHOLDER}
}
override fun onBindViewHolder(holder: ${VIEWHOLDER}, position: Int) {
}
override fun getItemCount(): Int {
return items.size
}
}
class ${VIEWHOLDER}(private val view: View) : RecyclerView.ViewHolder(view) {
}
@sjthn
Copy link
Author

sjthn commented Feb 8, 2018

To create the template,

  1. Choose Ctrl + Shift + A for Windows, Command + Shift + A for Mac, and type "File and Code Templates" and click it.
  2. Click the green plus icon and give the template name and its extension.
  3. Then paste this code.

To use this template go to the New submenu to find the name of the template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment