Simple Listview In Android – Example

Now, We are publish of simple listview example in Android Studio.

In this example, We can give you simple introduction of Listview. It is basic example of Listview Tutorials.

This example use for beginner user who dont know about the android. It is simple example of Listview Tutorials.

Below are the code of the Simple Listview App.

First of all you have to create New Project which is called “Simple Listview” or anything else.

Now Below are the code of

package com.web.simple.listview;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    ListView lst_CountryName;
    // Defined Array values to show in ListView
    String[] worldValues = new String[]{"India",
            "United States",

    protected void onCreate(Bundle savedInstanceState) {

        // Get ListView object from xml
        lst_CountryName = (ListView) findViewById(;

        // Define a new Adapter
        // First parameter - Context
        // Second parameter - Layout for the row
        // Third parameter - ID of the TextView to which the data is written
        // Forth - the Array of data

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,, worldValues);

        // Assign adapter to ListView

        // ListView Item Click Listener
        lst_CountryName.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                // ListView Clicked item index
                int itemPosition = position;

                // ListView Clicked item value
                String itemValue = (String) lst_CountryName.getItemAtPosition(position);

                // Show Alert
                Toast.makeText(getApplicationContext(), " Click Country Name : " + itemValue, Toast.LENGTH_LONG)



Now In XML File.


<!--?xml version="1.0" encoding="utf-8"?-->
<RelativeLayout xmlns:android=""

        android:layout_height="wrap_content" />


Now output of the project is given below.

Here is the screenshot.

Leave a Comment