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

  • 19 May

    Read CSV Line by Line in Python

    Table of ContentsRead CSV Line by Line Using the readline() Method in PythonRead CSV Line by Line Using the readlines() Method in PythonRead CSV Line by Line Using CSV Module in PythonRead CSV Line by Line Using the reader() MethodRead CSV Line by Line Using the DictReader() MethodConclusion CSV files or comma-separated files are used […]

  • 19 May

    Delete File if It Exists in Python

    Table of ContentsDelete File if Exists Using the os.remove() MethodDelete File if Exists Using the os.unlink() Method  Conclusion Python provides us with various tools to perform file handling operations. In this article, we will discuss different ways to delete file if it exists in the file system using python. Delete File if Exists Using the os.remove() […]

  • 19 May

    Convert Bytes to Int in Python

    Table of ContentsHow to Convert Bytes to Int in Python?How to Convert Bytes to Signed Int in Python?How to Convert Bytes to Unsigned Int in Python?Conclusion In this post, we will see how to convert Bytes to Int in Python. Normally, the data is stored in the storage in bytes format. In this article, we […]

  • 19 May

    Remove Extension From Filename in Python

    Table of ContentsHow to Remove Extension From Filename in Python?Remove Extension From Filename in Python Using the os ModuleRemove Extension From Filename in Python using the pathlib moduleRemove Multiple File Extensions Using pathlib Module in PythonConclusion While programming in python, we often have to deal with file names. In this article, we will discuss how […]

  • 19 May

    Get Type of Object in C++

    Table of ContentsWhy Should We Determine the Type of Object in C++: Dynamic DispatchingGet Type of Object in C++Conclusion C++ is an object-oriented language where we often interact with objects of different types. The object interaction becomes more interesting when we add runtime polymorphism to it. The runtime polymorphism, also known as, dynamic dispatch of […]

  • 19 May

    Remove First and Last Character of String in Python

    Table of ContentsHow to Remove First and Last Character of string in python?Remove First and Last Character of string Using For LoopRemove First and Last Character of string Using SlicingRemove First and Last word of string in PythonConclusion We use strings in python to handle text data. For processing the data, we sometimes need to […]

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.