Thursday 15 November 2012

Steps to design ListView in Android ?

Steps:
1.Create the xml file with ListView
Ex:
<ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

2.Get the reference of ListView to the Acivity.
Ex:
ListView list = (ListView) findViewById(R.id.list);

3.Create the String array with the suggestion values.
Ex:
String[] languages = { "Android", "Java", "xml", "Dot Net", "c", "Cpp","Oracle"};

4.Create the ArrayAdapter object for holding the suggestion Values.
Ex:
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(),
android.R.layout.simple_list_item_1, languages);

5.Attach the ArrayAdapter object to ListView.
Ex:
list.setAdapter(adapter);

No comments:

Post a Comment