What I did for this was to subclass RelativeLayout. This layout has a Gallery and a TextView (that serves as the title).
All of my code for setting the title based on the currently selected Gallery item is done in the subclassed RelativeLayout. Once I started doing this it was actually pretty straightforward to implement. You can actually see it in action here: https://market.android.com/details?id=com.magouyaware.appswipe Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Mon, Jun 27, 2011 at 4:53 AM, Mark Murphy <[email protected]>wrote: > Have your BaseAdapter hold onto the Activity, supplied via a > constructor parameter. Then, call findViewById() on it. > > On Mon, Jun 27, 2011 at 12:16 AM, Kivak <[email protected]> wrote: > > 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 > > > > > > -- > Mark Murphy (a Commons Guy) > http://commonsware.com | http://github.com/commonsguy > http://commonsware.com/blog | http://twitter.com/commonsguy > > Android Training in NYC: http://marakana.com/training/android/ > > -- > 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 > -- 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

