Home >> Miscellaneous
Android's Gallery element used in this Example to show multiple
Image views in a slider/spinner mode.
In this example I am going to try showing up set of ImageViews by
adding these along with Gallery View element/API from Android's API.
For this example I have created following images:
GalleryImagesProject.java
package com.techienjoy.example.gallery;
import android.app.Activity;
import android.content.Context;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.SpinnerAdapter;
public class GalleryImagesProject extends Activity {
Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
context = getApplicationContext();
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ExampleSpinnerAdapter());
}
private class ExampleSpinnerAdapter implements SpinnerAdapter {
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
return null;
}
@Override
public int getCount() {
return 4;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public int getItemViewType(int position) {
return 0;
}
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
ImageView imView = null;
if(position == 0) {
imView = new ImageView(context);
imView.setImageResource(R.drawable.camera1);
}
if(position == 1) {
imView = new ImageView(context);
imView.setImageResource(R.drawable.camera2);
}
if(position == 2) {
imView = new ImageView(context);
imView.setImageResource(R.drawable.camera3);
}
if(position == 3) {
imView = new ImageView(context);
imView.setImageResource(R.drawable.camera4);
}
return imView;
}
@Override
public int getViewTypeCount() {
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
}
}
}
|
Above source code has many methods left unimplementated as these methods
are not going to help directly in achiving objective of this example.
Method getView returns appropriate view based on the position argument
parameter value.
getCount method shows count value for number of images to be used for
showing on spinner widget.
Android Manifest file for this example, that is automatically generated:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.techienjoy.example.gallery"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".GalleryImagesProject"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Gallery android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/gallery1">
</Gallery>
</LinearLayout>
|
After building up these files along with image files in appropriate
folders such as four images are copied into folder "drawable" under
'res' folder, we have the following screen shot as shown in
Android Emulator.

I have used Android version 2.1-update1 SDK for this example.

If anything missed out , please let me know at
techienjoy at yahoo . com
|
|
| Android Examples : |
List of ANDROid examples
with source code and output
screens captured and shown.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Android Sensors Example : |
Example on Android Sensors Listed and
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Google GWT Example : |
Example using GWT and some design patterns and various
ways of implementing this example.
|
|
|
|
|
| Android ListView Example : |
Example on Android ListView
explained with a very simple scenario
whereby showing folder and files with
structure and appropriate screens
captured and shown.
|
|
| Android ListView Example : |
Example on Android List View
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
| Android Gallery Example : |
Example on Android Gallery View
explained with a very simple scenario
and appropriate screens captured and shown.
|
|
| Android ListView Example : |
Example on Android ListView and
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
|
|
|
|
|
|
|
|
|
|
|
| Android Tab View Example : |
Example on Android Tab View
explained with a very simple scenario
and appropriate screens captured and shown.
|
|
|
|