Android Custom ListView that Open New Activity to Display Clicked Item

In this tutorial we shall learn how to create android custom listview that Open new activity to display clicked item. Our ListView will have Image,Text and OnItemClickListener to listen when an item is clicked then open another activity and display clicked items. The list will consist of images and names of various fruits, When a list item is clicked another activity opens and display both image and name of the clicked item as shown below.

  • Preview of activity_main file
  • Android ListView

    Downloading Fruit image

  • Use the link below to download fruit images used used in this tutorial
  • download images

    Creating Resource Layout File for holding listview data

  • Right click layout => New => Layout Resource File and name it row_data.
  • Copy and Paste the code below to your row_data.xml file.
  • Preview of row_data file show below.
  • row data file

    Creating activity to receive and display clicked item

  • Right click on Layout => New => Activity => Empty Activity => name it in this case i have named it activity_listdata
  • open your activity_listdata, Copy and Paste the code below.

    Receiving and displaying clicked items

  • We are going to use intents to send and receive clicked item.
  • To send data between activities through intent we use
  • To receive through intent we use
  • Open your ListdataActivity, Copy and Paste the code below for receiving and displaying clicked item.

    Initializing ListView and Setting ListView Data

  • Open your MainActivity.java class
  • We shall start with initializing our listview and then set data list view data.
  • To set list view data we need to create custom Adapter that extends base Adapter.
  • Copy and Paste the code below in your MainActivity.java.

    Running our app

  • Run your app and you will see the output below.
  • Android ListView  OnItemClick Open New Activity With Clicked Item

  • Click on one of the item and you will see another activity with name and image of clicked item.
  • Android ListView  OnItemClick Open New Activity With Clicked Item

    Click here to download source code

  • That’s all if you have a question or need help please comment below.