SHARE
TWEET

Adapter

a guest Jan 29th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package app.simple.chat.projekt.lpptrola.adapter
  2.  
  3. import android.content.Context
  4. import android.support.annotation.NonNull
  5. import android.support.constraint.ConstraintLayout
  6. import android.support.v7.widget.RecyclerView
  7. import android.util.Log
  8. import android.view.LayoutInflater
  9. import android.view.View
  10. import android.view.ViewGroup
  11. import android.widget.TextView
  12. import app.simple.chat.projekt.lpptrola.R
  13.  
  14. class RecyclerViewStationNameAdapter(private val mContext: Context?, internal var itemListener: RecyclerViewStationNamesListener) : RecyclerView.Adapter<RecyclerViewStationNameAdapter.RecyclerViewStationNameHolder>() {
  15.     var arrSize = 0
  16.     var busNames: MutableList<Pair<String, Boolean>>? = mutableListOf()
  17.  
  18.     override fun onCreateViewHolder(@NonNull parent: ViewGroup, viewType: Int): RecyclerViewStationNameHolder {
  19.         val inflater = LayoutInflater.from(parent.context)
  20.         val v = inflater.inflate(R.layout.bus_station_name, parent, false)
  21.         return RecyclerViewStationNameHolder(v)
  22.     }
  23.  
  24.     override fun getItemCount(): Int {
  25.         return busNames?.size!!
  26.     }
  27.  
  28.     override fun onBindViewHolder(@NonNull holder: RecyclerViewStationNameHolder, position: Int) {
  29.  
  30.         if (busNames != null && busNames!!.size > 0) {
  31.             val nk = busNames!![position].first
  32.             holder.stationName?.text = nk
  33.             holder.bind(nk, itemListener)
  34.         }
  35. //        itemListener.onStationClicked(nk)
  36.  
  37.     }
  38.  
  39.     fun updateStationNames(stationsArr: MutableList<Pair<String, Boolean>>) {
  40.         busNames = stationsArr
  41.     }
  42.  
  43.  
  44.     class RecyclerViewStationNameHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  45.         var stationName: TextView? = null
  46.         var stationBackground: ConstraintLayout? = null
  47.  
  48.         init {
  49.             this.stationName = itemView.findViewById(R.id.stationName)
  50.             this.stationBackground = itemView.findViewById(R.id.stationPlaceHolder)
  51.         }
  52.  
  53.         fun bind(busName: String, clickListener: RecyclerViewStationNamesListener) {
  54.             stationBackground?.setOnClickListener { clickListener.onStationClicked(busName) }
  55.         }
  56.     }
  57.  
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top