Created
February 1, 2018 05:16
-
-
Save AkshayChordiya/e67fd595567f2f139936b54d23f3ea29 to your computer and use it in GitHub Desktop.
File Template for Android Studio to instantly create RecyclerViewAdapter in Kotlin without boilerplate
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.* | |
#parse("File Header.java") | |
class ${NAME} : RecyclerView.Adapter<${ViewHolder_Class}>() { | |
private var data: List<${Model_Class}> = ArrayList() | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ${ViewHolder_Class} { | |
return ${ViewHolder_Class}( | |
LayoutInflater.from(parent.context) | |
.inflate(R.layout.${Item_Layout_ID}, parent, false) | |
) | |
} | |
override fun getItemCount() = data.size | |
override fun onBindViewHolder(holder: ${ViewHolder_Class}, position: Int) = holder.bind(data[position]) | |
fun swapData(data: List<${Model_Class}>) { | |
this.data = data | |
notifyDataSetChanged() | |
} | |
class ${ViewHolder_Class}(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
fun bind(item: ${Model_Class}) = with(itemView) { | |
// TODO: Bind the data with View | |
setOnClickListener { | |
// TODO: Handle on click | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment