ListView (Displaying String Array)

ListView (Displaying String Array)


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=""
	android:orientation="vertical" android:layout_width="fill_parent"
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:id="@+id/txt" />
	<ListView android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:id="@+id/List" />

Activity file

package com.androidwork.adapterdemo;

import android.R.string;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Gallery;
import android.widget.ListView;
import android.widget.TextView;

public class AdapterDemoActivity extends Activity {
	/** Called when the activity is first created. */
	ListView list;

	public void onCreate(Bundle savedInstanceState) {
		final String[] items = new String[] { "Item1", "Item2", "Item3",
				"Item4" };

		ArrayAdapter ad = new ArrayAdapter(
				getApplicationContext(), android.R.layout.simple_list_item_1,
		list = (ListView) findViewById(;
		// list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

		list.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				TextView txt = (TextView) findViewById(;
				txt.setText("It is : " + arg2);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s