MainActivity.java:

package com.example.appone;

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

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    ListView listView;

    String[] contacts = {
            "Babu",
            "Akhil",
            "Anand",
            "Arjun",
            "Athul",
            "David",
            "Hari",
            "John",
            "Rahul",
            "Riya",
            "Sneha",
            "Thomas"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = findViewById(R.id.listViewContacts);

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

                        contacts);

        listView.setAdapter(adapter);

        listView.setOnItemClickListener((parent, view, position, id) ->

                Toast.makeText(
                        MainActivity.this,
                        "Selected : " + contacts[position],
                        Toast.LENGTH_SHORT
                ).show()

        );
    }
}


activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Contacts List"
        android:textSize="24sp"
        android:textStyle="bold"
        android:gravity="center"
        android:paddingBottom="15dp"/>

    <ListView
        android:id="@+id/listViewContacts"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>
