Listview in Android Studio

Android Studio Listview:

There are multiple ways of displaying data in Android Studio Recyclerview, Listview

Listview is used to display the number of entries in a selected layout to be displayed,

it’s an advanced version is Recyclerview

MainActivity.XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >
    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/list"
        >

    </ListView>

    </LinearLayout>

MainActivity.Java:

Just create a list of names or anything according to your need in main activity

package com.example.listview;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {
    String listname[]={"John","Obama","Jacky","Doanld","Vicky","KFC","MCdonlad","Tom","Cruise","Vin"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main );
        ListView listView = (ListView) findViewById( R.id.list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listname);
        listView.setAdapter(adapter);

    }
}
Listview in Android Studio