Tuesday, 16 October 2012

ANDROID - ListView Example
























ListViewActivity.java:

package com.venkool;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListViewActivity extends Activity {
    /** Called when the activity is first created. */

ListView lvList;

final String[] str={"Hyderabad","Bangalore","Chennai","Delhi","India","Srilanka","USA","UK"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        lvList=(ListView)findViewById(R.id.lvList);
       
        ArrayAdapter adapter=new ArrayAdapter(getApplicationContext(), android.R.layout.simple_list_item_1,str);
       
        lvList.setAdapter(adapter);
    }
}

main.xml:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="List View Demo" />
   
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/lvList">
       
    </ListView>

</LinearLayout>


No comments:

Post a Comment