Thursday, 20 September 2012

Simple Listview Activity

 
 
 This is a simple ListActivity which extends ListActivity
 
 Country_list.java
 
 
 package com.example.Listview;
 
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class Country_list extends ListActivity {
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    String[] values = new String[] { "India", "Pakistan", "Sri Lanka",
        "China", "Bangladesh" ,"Nepal","Afghanistan"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_1, values);
    setListAdapter(adapter);
  }
} 
 
 
main.xml 
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>  
 
Screenshot for the application
 

No comments:

Post a Comment