Android Simple ListView Example - ANDROID - Helper

Thursday, March 10, 2011

Android Simple ListView Example


SIMPLE LISTVIEW
 

SOURCE CODE [main.xml] is 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android">
                <ListView android:id="@+id/listview"
android:layout_width="wrap_content"
                                android:layout_height="wrap_content" />
</LinearLayout>



SOURCE CODE [ListViewExample.java] is 

package com.ListViewExample;

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

public class ListViewExample extends Activity
{
                private ListView lv;
                private String listview_array[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
                                                "SEVEN", "EIGHT", "NINE", "TEN" };

                public void onCreate(Bundle icicle)

{
                                super.onCreate(icicle);
                                setContentView(R.layout.main);
                                lv = (ListView) findViewById(R.id.listview);
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listview_array));
                }
}
 

The OUTPUT will be

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNOvVZFmKCq61WYMAqOlDIv4lqdUcwpCEnBOuI-Zw3ITSrOR7p77P0U8VLMXkf7gABJPVyvC6_4z-GRRw-4yg1fzyhglB5EL5QohcB17ZhCGpEx8XNyq4FTtS6QhDhFcoYBA2EnDA43ns/

No comments:

Post a Comment