Last active
October 6, 2017 08:30
-
-
Save anujmiddha/2ad11a6e9f50d104d6991e7b60822422 to your computer and use it in GitHub Desktop.
Android Studio Template for RecyclerViewAdapter
This file contains 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 | |
#parse("File Header.java") | |
class ${NAME} : RecyclerView.Adapter<${NAME}.${VH_NAME}>() { | |
private val items: MutableList<${MODEL}> = mutableListOf() | |
fun clear() { | |
items.clear() | |
} | |
fun addAll(newItems: List<${MODEL}>) { | |
items.addAll(newItems) | |
} | |
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ${VH_NAME} { | |
val inflater = LayoutInflater.from(parent?.context) | |
return ${VH_NAME}(inflater.inflate(R.layout.list_item, parent, false)) | |
} | |
override fun onBindViewHolder(holder: ${VH_NAME}?, position: Int) { | |
TODO() | |
} | |
override fun getItemCount(): Int { | |
return items.size | |
} | |
class ${VH_NAME}(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment