In Android, Listview is used to show a list of items in a vertically scrolling list.
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
*********************************************
xml version="1.0" encoding="utf-8"?> |
2 | <LinearLayout android:id="@+id/LinearLayout01" |
3 | android:layout_width="fill_parent" |
4 | android:layout_height="fill_parent" |
6 | <ListView android:id="@+id/ListView01" |
7 | android:layout_width="wrap_content" |
8 | android:layout_height="wrap_content" /> |
Your Java code looks like
01 | public class ListviewExample extends Activity |
04 | private String lv_arr[]={"Android","iPhone","BlackBerry","AndroidPeople"}; |
06 | public void onCreate(Bundle icicle) |
08 | super.onCreate(icicle); |
09 | setContentView(R.layout.main); |
10 | lv1=(ListView)findViewById(R.id.ListView01); |
12 | lv1.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1 , lv_arr)); |
The output will look like
No comments:
Post a Comment