Slide 5
Slide 5 text
Custom Adapter
class BookAdapter: BaseAdapter() {
override fun getCount(): Int = dataSource.size
override fun getItem(position: Int): Any = dataSource[position]
override fun getItemId(position: Int): Long = position.toLong()
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val rowView = inflater.inflate(R.layout.list_book_item, parent, false)
val titleTextView = rowView.findViewById(R.id.book_title) as TextView
val authorTextView = rowView.findViewById(R.id.book_author) as TextView
// populate book data to itemview
val book = getItem(position) as Book
titleTextView.text = book.title
authorTextView.text = book.author
return rowView
}
}