Wednesday, October 5, 2022

How to implement simple ListView in android

- Advertisement -

How to implement simple ListView in Android

Here I am going to show you how to implement simple ListView in android. First of all, you need to know what is list view and how it works in android then we will move towards the implementation.

What is ListView :

List view is a list of items having the same view or you can say the presentation. In android, Adapter is used to hold the list item which then binds items to the listview. Adapter fetches the data from the data source like the array or from the cursor which stores the result of the database query. Now we will see the actual implementation of a list view.

Implement simple ListView in android :

- Advertisement -

To implement simple listview in android follow the below steps :

  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 data source. Create string array inside res -> values-> string.xml as below.
    <string name="app_name">ListViewExample</string>

    <string-array name="types_of_os">
        <item>Android OS (Google Inc.)</item>
        <item>Bada (Samsung Electronics)</item>
        <item>BlackBerry OS (Research In Motion)</item>
        <item>iPhone OS / iOS (Apple)</item>
        <item>MeeGo OS (Nokia and Intel)</item>
        <item>Palm OS (Garnet OS)</item>
        <item>Windows Mobile (Windows Phone 7)</item>
  1. Create the layout for the single item of a list. res » layout » right click » Layout resource file » give a name listview_item.xml  then press OK.


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


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" android:layout_width="match_parent"


  1. Now open SimpleListViewActivity from java package and copy the below text.
package com.buzzmycode.listviewexample;

import android.os.Bundle;
import android.widget.ArrayAdapter;

public class SampleListViewActivity extends ListActivity {

    protected void onCreate(Bundle savedInstanceState) {

        String[] mobile_os = getResources().getStringArray(R.array.types_of_os);
        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.listview_item,, mobile_os));

  1. Finally, Open your AndroidManifest.xml from a manifest package and add make changes to your AndroidManifest file as below.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

        <activity android:name=".SampleListViewActivity">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

  1. Now run your project you will see the output as shown below.
Simple ListView in Android

I hope this would have helped you. For any query you can comment below, I am always ready to help you.

Aasim Sheikh
Aasim Sheikh
CTO at SyncSaS Technologies

Stay in Touch

To follow the best weight loss journeys, success stories and inspirational interviews with the industry's top coaches and specialists. Start changing your life today!

Related Articles