Sat. Jul 13th, 2024

ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that’s placed into the list.

Syntax for List view

ListView listView;
ArrayAdapter arrayAdapter=new ArrayAdapter(Context(),
         layout Resource,ArrayResource);

In ArrayAdapter return type is 3 arguments

  1. Context
    1. Layout Resource
    1. Array Resource

Context: Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

In Android Context we can write in 3 ways

  1. SuperClassName.this
  2. getApplicationContext()
  3. getActivity()

(This we can use only in Fragments.)

Layout Resource: Layout Resource we can specify in 2 ways

1. Predefined layout

2. Custom Layout

Array Resource: Array Resource we can specify in 3 ways

1. Array from Java

2. Array From Xml

3. Array From Database(Server)

Will observe below with different programs with above combinations

Program: ListView with predefined Layout & Array from Java


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
        android:text="ListView Example"
        android:gravity="center"   />
        android:id="@+id/listviewex"  />

package androiindians.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 listView;
    String[]Course={"Android","CoreJava","Adv  Java"};
    protected void onCreate(Bundle savedInstanceState) {
        listView= (ListView) findViewById(;
//predefined layout +array from Java
       ArrayAdapter arrayAdapter=new ArrayAdapter(getApplicationContext(),

By Rajashekar

I’m (Rajashekar) a core Android developer with complimenting skills as a web developer from India. I cherish taking up complex problems and turning them into beautiful interfaces. My love for decrypting the logic and structure of coding keeps me pushing towards writing elegant and proficient code, whether it is Android, PHP, Flutter or any other platforms. You would find me involved in cuisines, reading, travelling during my leisure hours.

Leave a Reply

Your email address will not be published. Required fields are marked *