Android List View

android listview
android listview

Using Android ListView we can arrange components in a vertically scrollable list. 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 on the list.

Attributes

android:id

Unique ID


android:divider

It separates the items.


android:entries

Defines the reference to an array that will fill the ListView.

Android ListView Example

strings.xml

 

<resources>
     <string name="app_name">ListView</string>
     <string-array name="Languages">
         <item>Android</item>
         <item>Java</item>
         <item>PHP</item>
         <item>Python</item>
         <item>ASP.NET</item>
         <item>HTML</item>
         <item>C#</item>
         <item>C++</item>
     </string-array>
 </resources>

activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:paddingBottom="@dimen/activity_vertical_margin"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
     tools:context="com.chirag.listview.MainActivity">
     
     <ListView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/listView"
         android:entries="@array/Languages"
         android:layout_alignParentTop="true"
         android:layout_alignParentLeft="true"
         android:layout_alignParentStart="true" />
     
 </RelativeLayout>

Output

listview

What is your reaction?

0
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
Carolyn Jenner

You may also like

Comments are closed.