Javatpoint Logo
Javatpoint Logo

Android ListView

Android ListView is a view which contains the group of items and displays in a scrollable list. ListView is implemented by importing android.widget.ListView class. ListView is a default scrollable which does not use other scroll view.

ListView uses Adapter classes which add the content from data source (such as string array, array, database etc) to ListView. Adapter bridges data between an AdapterViews and other Views (ListView, ScrollView etc).

Example of ListView

Let's implement a simple listview example.

Structure of listview project

android Listview 1

activity_main.xml

First we need to drag and drop ListView component from palette to activity_main.xml file.

File: activity_main.xml

Create an additional mylist.xml file in layout folder which contains view components displayed in listview.

mylist.xml

File: mylist.xml

Now place the list of data in strings.xml file by creating string-array.

strings.xml

File:strings.xml

Activity class

In java class we need to add adapter to listview using setAdapter() method of listview.

File: MainActivity.java

Output

android Listview 2
android Listview 3




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials