Thursday 31 January 2013

ListView Demo

Demo:
 


1.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:background="#5F04B4"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

</LinearLayout>

2.Activity:
package com.venky.listviewdemo;

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

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

      ListView listview;

      String[] Languages = { "Telugu", "English", "Hindi", "Tamil", "Kanada",
                  "Urdu", "Punjabi", "etc" };

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            listview = (ListView) findViewById(R.id.listView1);

            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                        ListViewDemoActivity.this, android.R.layout.simple_list_item_1,
                        Languages);

            listview.setAdapter(arrayAdapter);
      }
}


3)Download this Project Click Here 
 

No comments:

Post a Comment