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 !!

Related Posts

  • 22 January

    FizzBuzz program in Python

    In this post, we will see how to program FizzBuzz in Python. As per wikipedia, Fizz buzz is a group word game for children to teach them about division. Here are the rules of the game: First player starts the game by saying number 1. Next player says next number but fun part is If […]

  • Format double to 2 decimal places in java
    22 January

    7 ways to format double to 2 decimal places in java

    Learn about how to format double to 2 decimal places in java

  • Escape double quotes in String in Java
    19 January

    How to escape double quotes in String in java

    In this post, we will see how to escape double quotes in String in java. There are scenarios where you need to escape double quotes already present in the String. This generally happens while dealing with JSON file format or reading file data. Escape double quotes in java Double quotes characters can be escaped with […]

  • Convert Date to LocalDate in java
    12 January

    Java Date to LocalDate

    In this post, we will see how to convert Date to LocalDate in java. Sometimes, we may need to convert Date to new Java 8 APIs and vice versa. There are multiple ways to convert Date to LocalDate in java. Read also: Convert LocalDate to Date in java Using toInstant() method of Date class You […]

  • Convert LocalDate to Date in java
    11 January

    Java LocalDate to Date

    In this post, we will see how to convert LocalDate to Date. Java 8 has introduced a lot of new APIs for Date and time. There can be many ways to convert Java LocalDateTime to date. Using Instant object You can convert LocalDate to Date using Instant object which we can from Zone. Here is […]

  • 04 January

    How to change java version in intellij

    Learn about how to change java version in intellij.

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.