ListView With ItemClickListener using Kotlin

Hi guys, In this tutorial we are going to learn how to implement ListView with ItemClickListener using Kotlin. In this tutorial we will display a list of fruit names, images and a short description which in this case we are going to use scientific name of that fruit, When an item is clicked we shall display a toast message showing the name of item clicked.

Adding fruits to drawable folder

  • Download fruit images by clicking the link below.
  • Unzip copy and paste the image in the drawable folder.
  • download fruits

    Creating Resource Layout file to hold RecyclerView data

  • Right click layout folder which is under res folder.
  • Select New => Layout Resource File and name it row_data.
  • This is the xml file which will hold the listview data.
  • Writing Custom Adapter that extends base adapter

  • Base Adapter is the general Adapter
  • We will use it to create list view items
  • Open your MainActivity copy and paste the code below.
  • That’s all, Run your app and you will have output similar to one shown below.
  • ListView with ItemClickListener using Kotlin

  • If you have a question or need help please comment below
  • To download source code click here
  • Learn how to create RecyclerView using kotlin