Listview Example : Getting started with Android
Today, we are going to see about a simple listview example. In Android, Listview is used to show a list of items in a vertically scrolling list. Learn a listview of android array in this tutorial.
For instance, in a Registration form when we are selecting professions a list of items will be displayed. We can use Listview to display the list of items.
Your XML file should look like
1
2
3
4
5
6
7
8
9
|
xml version="1.0" encoding="utf-8"?>
LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
/LinearLayout>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
public class ListviewExample extends Activity
{
private ListView lv1;
private String lv_arr[]={"Android","iPhone","BlackBerry"};
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
lv1=(ListView)findViewById(R.id.ListView01);
// By using setAdpater method in listview we an add string array in list.
lv1.setAdapter(new ArrayAdapter
}
}
|
0
0