Android Basics – Learn how to handle Clicks in a ListActivity using onListItemClick

By now you should be familiar with a ListActivity and how to use this to display items.

So what happen’s when a user clicks on an item. How can you handle that ?

The good news is that you don’t need to use an EventListener. You can simply override onListItemClick method.

@Override
public void onListItemClick(ListView listView, View itemView, int position, long id){
    //Implement your Logic
    //Here id param is id of the item clicked. It can also be the DB unique id
}

Source code is available here

Android Basics – Learn how to use a ListActivity to display and manage a List of Items

 

In the last Post you got familiar with using a ListView to display a list of items which came from a static String Array.

You can also accomplish the same using a ListActivity.

Why use ListActivity ?

A ListActivity class is quite useful as you don’t need to create a Layout file.

You have the option to create your own Layout file, but it’s not mandatory.

Also you don’t need to create an Event Listener. In order to use the ListActivity you will need to extend this class.

public class ScrollingActivity extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

}

Follow the Video in which I will guide you to create a new ListActivity to display the items.

Source Code is available here