Last active
September 30, 2023 10:50
-
-
Save lopspower/57864633285d8695603b84c8b680df5b to your computer and use it in GitHub Desktop.
RecyclerView Adapter Kotlin Android Studio Template
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 | |
import java.util.* | |
class ${NAME} : RecyclerView.Adapter<${Model}Adapter.ViewHolder>() { | |
var data: MutableList<${Model}> = mutableListOf() | |
set(value) { | |
field = value | |
notifyDataSetChanged() | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder = | |
ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.${Item_Layout_ID}, parent, false)) | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(data[position]) | |
override fun getItemCount() = data.size | |
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
fun bind(item: ${Model}) = with(itemView) { | |
// TODO: Bind the data with View | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Highly recommend you to check out one good lib for reducing this boilerplate in your sources: https://github.com/sockeqwe/AdapterDelegates