Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
  2.  
  3. import android.support.v7.widget.RecyclerView
  4. import android.view.LayoutInflater
  5. import android.view.View
  6. import android.view.ViewGroup
  7.  
  8. #parse("File Header.java")
  9.  
  10. class ${NAME} (val items: List<${ITEM_CLASS}>, val itemClick: (${ITEM_CLASS}) -> Unit) : RecyclerView.Adapter<${NAME}.${VIEWHOLDER_CLASS}>() {
  11.  
  12. override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ${VIEWHOLDER_CLASS} {
  13. val view = LayoutInflater.from(parent.context).inflate(R.layout.${LAYOUT_RES_ID}, parent, false)
  14. return ${VIEWHOLDER_CLASS}(view, itemClick)
  15. }
  16.  
  17. override fun onBindViewHolder(holder: ${VIEWHOLDER_CLASS}, position: Int) {
  18. holder.bindView(items[position])
  19. }
  20.  
  21. override fun getItemCount(): Int = items.size ?: 0
  22.  
  23.  
  24. class ${VIEWHOLDER_CLASS}(val view: View, val itemClick: (${ITEM_CLASS}) -> Unit) : RecyclerView.ViewHolder(view) {
  25.  
  26. fun bindView(item: ${ITEM_CLASS}) {
  27. with(item) {
  28. itemView.setOnClickListener { itemClick(this) }
  29. }
  30.  
  31. }
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement