ListView In Android Studio with Example

ListView in Android is ViewGroup used to display the list of items in more than one row and ListView in Android contains an adapter that is useful to automatically insert items to the list. So ListView in Android is a very important Component.

Items are inserted into the list from an Array of Databases using an Adapter. And to display the content of the list setAdapter() method is used. The main Application of the Adapter is to fetch data from an Array or Database and insert every item into the list.

setAdapter(): use it when the Adapter and list need to join.

You can also watch YouTube videos from our channel. To implement ListView in Android Studio

ListView In Android

The steps to Create ListView In Android

1. So, the first step is to Open Android Studio and create a new Project. Click “New Project” to create a new Project

Create New Project for ListView in Android

2. So now the Android Studio screen of multiple Activity will appear Select Empty Activity.

Select Activity of Application

3. Next give the name of the Application. And select the place where do you want to store the application file. And the language in which you want to create an application either JAVA or KOTLIN. We are using Java in this tutorial. Now we have to select the Minimum SDK version of the Android Application which is the least SDK to run the Android Application. Click “Finish” to proceed.

Naming the Application

4. So Default Hello world application will be ready to use after the build is successfully created of the Android Application.

XML file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=""

        android:text="Hello World!"
        app:layout_constraintTop_toTopOf="parent" />


JAVA file:

package com.example.listviewexample;


import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {


Hello world

5. Open the activity_main.xml file to edit and add the following code instead of the default TextView. Only change the TextView.


6. So now open and create the object for ListView.

ListView listView;

7. And create a String and ArrayAdapter.

String[] listItems = {"Itme one", "Item two", "Item three"};
ArrayAdapter<String> adapter;

8. So now initialize listview with id “list”.

listView = findViewById(;

9. Now create a New Empty Resource Layout file to use the list. by right-clicking the res folder and clicking on “New” and adding a new Resource Layout file.

Creating New Layout File for ListView in Android
Layout Files for ListView in Android

So, open this file and add TextView to this file.

        android:id="@+id/listText" />

10. So, Now initialize the ArrayAdapter with and pass the layout to the constructor

adapter = new ArrayAdapter<>(this, R.layout.list_items,, listItems);

And this will contain 4 parameters

  • Context
  • Layout
  • Id of the text view
  • An array of the List Items

So now set the Adapter to the ListView


11. So now set on click listener to the ListView. So whenever the user clicks on any item of ListView a toast message of the content from that list item will be displayed.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //step 8 getting value form list
                String value = adapter.getItem(position);
                Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT ).show();


ListView Output

So in this article, we have seen how to implement Listview in Android Studio and how we can set the method setOnClickListener on it and whenever the user clicks on the Items of the list and same Content of that list items will display as toast method.

Read more:

Leave a Comment