Skip to content

Instantly share code, notes, and snippets.

@IEnoobong
Last active December 9, 2017 14:18
Show Gist options
  • Save IEnoobong/52456df2737d294feb779a050da1fb74 to your computer and use it in GitHub Desktop.
Save IEnoobong/52456df2737d294feb779a050da1fb74 to your computer and use it in GitHub Desktop.
Works but not sustainable
class Hotel(val name: String, val address: String, val hasPool: Boolean, val hasWifi: Boolean){
override fun toString(): String {
return "Hotel(name='$name', address='$address', hasPool=$hasPool, hasWifi=$hasWifi)"
}
}
class HotelAdapter(context: Context, @LayoutRes private val layoutResource: Int, private val hotels: List<Hotel>):
ArrayAdapter<Hotel>(context, layoutResource, hotels) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
return createViewFromResource(position, convertView, parent)
}
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup?): View {
return createViewFromResource(position, convertView, parent)
}
private fun createViewFromResource(position: Int, convertView: View?, parent: ViewGroup?): View{
val view: TextView = convertView as TextView? ?: LayoutInflater.from(context).inflate(layoutResource, parent, false) as TextView
view.text = hotels[position].name
return view
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment