How to handle ListItem click in Android

How to handle ListItem click in Android

How to handle List Item click in Android

Creating a simple ListView in an easy task, you can check my tutorial for simple listview. But list view that does not handle click is no mean. In this tutorial, we will discuss how to handle the click event on a listview item.

If you ever have implemented my simple I tutorial and want to handle click event, you just need to add the below code to the SimpleListViewActivity which is responsible for handling the click on a list Item.

Here is the brief of creating a list view with the click on its item. I am going to show you how to handle click on a listview item with a simple Toast that will appear showing item and position of the particular item when you click on any item of the ListView.

  1. Create the new project in Android Studio as File ->New-> New Project.
  2. Name your project whatever you want and rename MainActivity as SimpleListViewActivity then select Finish.
  3. We want data that will display in list view, here I am using an array as a Datasource. Create string array inside res -> values-> string.xml as below.

4. Create layout for the single item an of a list. res » layout » right click » Layout resource file » give a name listview_item.xml  then press OK.

5. Copy the below code to the listview_item.xml.

6. Now open SimpleListViewActivity from java package and copy the below text.

7. Finally, Open your AndroidManifest.xml from a manifest package and add make changes to your AndroidManifest file as below.

8. Now run your project you will see the output as shown below.



Here we did with Simple ListView with the click on its item. I hope you found it helpful. For any query comment below I would love to solve it.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular

Buzzing your life from assorted Coding,tips and general life opinion. Made your life Buzz by BuzzMyCode articles, share with world.

What is Buzzmycode, we had started this website to give tech savy the new way of life by reading our fresh organic content on every technology and applications.

Copyright © 2017 SyncSaS. Theme by SyncSaS Themes, powered by BuzzMyCode.

To Top