Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 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} (var 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. fun setData(newDataSet: MutableList<${ITEM_CLASS}>){
  18. items = newDataSet.toList()
  19. notifyDataSetChanged()
  20. }
  21.  
  22. override fun onBindViewHolder(holder: ${VIEWHOLDER_CLASS}, position: Int) {
  23. holder.bindView(items[position])
  24. }
  25.  
  26. override fun getItemCount(): Int = items.size ?: 0
  27.  
  28. class ${VIEWHOLDER_CLASS}(val view: View, val itemClick: (${ITEM_CLASS}) -> Unit) : RecyclerView.ViewHolder(view) {
  29.  
  30. fun bindView(item: ${ITEM_CLASS}) {
  31. with(item) {
  32. itemView.setOnClickListener { itemClick(this) }
  33. }
  34.  
  35. }
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement