Last active
January 10, 2019 14:28
-
-
Save sijangurung/fe6cad0b5dbe7bd7f5018b4bcb450478 to your computer and use it in GitHub Desktop.
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} (val items: List<${ITEM_CLASS}>, val itemClick: (${ITEM_CLASS}) -> Unit) : RecyclerView.Adapter<${NAME}.${VIEWHOLDER_CLASS}>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ${VIEWHOLDER_CLASS} { | |
val view = LayoutInflater.from(parent.context).inflate(R.layout.${LAYOUT_RES_ID}, parent, false) | |
return ${VIEWHOLDER_CLASS}(view, itemClick) | |
} | |
override fun onBindViewHolder(holder: ${VIEWHOLDER_CLASS}, position: Int) { | |
holder.bindView(items[position]) | |
} | |
override fun getItemCount(): Int = items.size | |
class ${VIEWHOLDER_CLASS}(val view: View, val itemClick: (${ITEM_CLASS}) -> Unit) : RecyclerView.ViewHolder(view) { | |
// here comes all the views / variables from view.findViewById() | |
// Example: val textView = view.findViewById(R.id.textView1) | |
fun bindView(item: ${ITEM_CLASS}) { | |
with(item) { | |
// here you do all kind of assignments and logics.. | |
// for Example: textView.text = item.name or just name | |
itemView.setOnClickListener { itemClick(this) } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment