= 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 } }
lateinit var authorTextView: TextView } override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { val rowView = inflater.inflate(R.layout.list_book_item, parent, false) val holder: ViewHolder = ViewHolder() holder.titleTextView = view.findViewById(R.id.book_title) as TextView holder.authorTextView = view.findViewById(R.id.book_author) as TextView // populate book data to itemview val book = getItem(position) as Book holder.titleTextView.text = book.title holder.authorTextView.text = book.author return rowView }
ViewHolder defining each of the element - recyclerview binds the viewholder to the data • Adapter defines methods where view is requested and binds to data • LayoutManager arranges the items in the list
into a large data set. • Faster , optimized performance • Versatile API • Recycled Views , dynamic list of data • Reduction in memory/power consumption • Enhanced responsiveness