Monday, June 18, 2012

How To Create List View In Android

The project describes how to implement list view for your application.
Underlying Algorithm:
Basic description of algorithm in step by step form:
1.) Create a Project ListViewExample
2.) Open and insert following in main.xml:
<LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent" android:layout_height="fill_parent"

        <ListView android:id="@+id/ListView01"android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
3.) Run the application.
Steps to Create:
1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. ListViewExample. Enter following information:
Project name: ListViewExample
Build Target: Android 2.3.3
Application name: ListViewExample
Package name: org.example.ListViewExample
Create Activity: ListViewExample
On Clicking Finish ListViewExample code structure is generated with the necessary Android Packages being imported along with ListViewExample class will look like following:
package org.example.ListViewExample;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListViewExample extends Activity {
        private ListView lv1;
        private String lv_arr[]={"Item1","Item2","Item3","Item4"};
        public void onCreate(Bundle icicle)
        // By using setAdpater method in listview we an add string array in list.
        lv1.setAdapter(newArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));
Output – The final output:

No comments:

Post a Comment