Last active
December 9, 2017 14:18
-
-
Save IEnoobong/52456df2737d294feb779a050da1fb74 to your computer and use it in GitHub Desktop.
Works but not sustainable
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
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