Hello everyone!

I am a pretty recent beginner to the android SDK and Java in general.
I've had experience in OOP programming, but most of my programming has
been in PHP and SQL - quite a bit different from Java as far as I can
tell.

My question pertains to the use of the Gallery wigit. I was able to
look up a couple tutorials on how to use the wigit and add photos into
it using an ImageAdapter (class extending the BaseAdapter) - even make
them full screen. But what I want to do is to add some text to the
screen as well which will change based on the photo that is there. For
example: the name of the photo itself.

My line of thinking was that I could use the "getView()" function in
the ImageAdapter class because it is called every time you scroll to
another image. But I cannot use "findViewById()" in the ImageAdapter
class (I assume because it extends BaseAdapter and not Activity).

Can anyone at least point me in the right direction of how to solve
this?

Thanks so much for your time and help!!
-Kivak



Code is as follows:

Wallpapers Class (the class called as intent)
--------------------------------------------------------------------

import android.app.Activity;
import android.os.Bundle;
import android.widget.Gallery;

public class Wallpapers extends Activity {
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.wallpapers);

        ((Gallery) findViewById(R.id.gallery)).setAdapter(new
WallpaperImageAdapter(this));
    }
}



ImageAdapter Class
---------------------------------------------------------------------

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Gallery.LayoutParams;

public class WallpaperImageAdapter extends BaseAdapter {

        /** The parent context */
        private Context myContext;

        /**
         * All images to be displayed. Put some images to project-folder:
         * '/res/drawable/uvw.xyz' .
         */
        private int[] myImageIds = { R.drawable.wallpaper_1,
                        R.drawable.wallpaper_2, R.drawable.wallpaper_3,
                        R.drawable.wallpaper_4 };

        /** Simple Constructor saving the 'parent' context. */
        public WallpaperImageAdapter(Context c) {
                this.myContext = c;
        }

        /** Returns the amount of images we have defined. */
        public int getCount() {
                return this.myImageIds.length;
        }

        /* Use the array-Positions as unique IDs */
        public Object getItem(int position) {
                return position;
        }

        public long getItemId(int position) {
                return position;
        }

        /**
         * Returns a new ImageView to be displayed, depending on the position
         * passed.
         */
        public View getView(int position, View convertView, ViewGroup parent)
{
                ImageView i = new ImageView(this.myContext);

                i.setImageResource(this.myImageIds[position]);
                /* Image should be scaled as width/height are set. */
                i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                /* Set the Width/Height of the ImageView. */
                i.setLayoutParams(new
Gallery.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
                return i;
        }


}




Wallpaper.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:id="@+id/gallery"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:gravity="fill_horizontal" />
</LinearLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to