Now that we've got the GalleryAdapter
working, we need to connect the Gallery
, the GalleryAdapter
, and the ImageView
together, so that when a thumbnail is selected, the full-view of that image is displayed in the ImageView
object.
Open the
ReviewActivity
source code in your editor or IDE.Add
AdapterView.OnItemSelectedListener
to the interfaces that theReviewActivity
implements.Below the declaration of the
TextSwitcher
, declare a reference to theImageView
which will hold the full-size image:private TextSwitcher switcher; private ImageView photo;
At the end of the
onCreate
method, find theImageView
namedphoto
and assign it to the reference you just declared:photo = ((ImageView)findViewById(R.id.photo));
Now fetch the
Gallery
object as declared in themain.xml
layout resource:Gallery photos = ((Gallery)findViewById(R.id.gallery));
Create a new
GalleryAdapter
and set it on theGallery
object:photos.setAdapter(new GalleryAdapter());
Set the
OnItemSelectedListener...