Simple Android ListView example

In this post , we are going to create simple ListView.
ListView is the view in which you arrange your list items in vertical order.
For example:

It is very popular widget which is used almost in every application. In this post, I am going to create a very simple list view . If you want to create a some what complex Listview which have images and text in same row , you can go through Android Custom ListView example.

Source code:

Step 1 :Creating Project

Create an android application project named “AndroidListViewExampleApp”.

Step 2 : Creating Layout

Change res ->layout -> activity_main.xml as below:

Step 3 : Creating MainActivity

Change src/main/packageName/MainActivity.java as below:

If you notice closely, our MainActivity extends ListActivity as ListActivity has some method specifically for ListView.

Whenever we create ListView, we need to provide ArrayAdapter which sets view for each row and also we need to provide a file which defines layout of each Row. In this example, we are using android.R.layout.simple_list_item_1 which is android’s predefined layout file .

Step 4 : Running the app

When you run the app, you will get below screen:

Android simple ListView example

When you click on Bhutan , you will get below screen

Android Simple ListView Tutorial

We are done with Android Simple ListView example.
Happy Android Learning !!

Was this post helpful?

Leave a Reply

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