Gallery (Displaying String Array)

Gallery (Showing array of string)


<?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:text="Gallery Demo"
		android:id="@+id/txt" />
	<Gallery android:id="@+id/gallery" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:gravity="center_horizontal"
		android:spacing="100px" android:scrollbars="horizontal" />

Activity file

package com.androidwork.gallerydemo;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Gallery;
import android.widget.TextView;

public class GalleryDemoActivity extends Activity {
	/** Called when the activity is first created. */
	Gallery gallery;

	public void onCreate(Bundle savedInstanceState) {

		gallery = (Gallery) findViewById(;
		// String array holding the values
		String[] text = new String[] { "Hello", "Hi", "Alloha", "Bonjour",
				"Hallo", "¡Hola" };
		// Array adapter to display our values in the gallery control
		ArrayAdapter<String> arr = new ArrayAdapter<String>(this,
				android.R.layout.simple_gallery_item, text);

		gallery.setOnItemSelectedListener(new OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				TextView txt = (TextView) findViewById(;

			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub




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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s