How to implement a textview that changes to match my image in a galleryview?
<p>I have a galleryview with some pictures of my local swans, and I would like to have a textview that changes with the pictures.  </p>

<p>My working code is below. At the moment I simply have a galleryview with an imageswitcher. 
From my googling I reckon I need to use an array adapter with text strings, but I haven't been able to find a way to make it work. As you can probably tell, I am very much in the early stages of learning Java!</p>

<p>Any help or advice pointing me in the correct direction would be very much appreciated. </p>

<p>Thanks</p>

<p>Mark</p>

<pre><code>public class MainMenuActivity extends Activity 
implements ViewFactory
{    
//---the images to display---
Integer[] imageIDs = {
        R.drawable.swan1,
        R.drawable.swan2,
        R.drawable.swan3,
        R.drawable.swan4,
        R.drawable.swan5,
        R.drawable.swan6                  
};

private ImageSwitcher imageSwitcher;

@Override    
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.displayview);

    imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher1);
    imageSwitcher.setFactory(this);
    imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
            android.R.anim.fade_in));
    imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
            android.R.anim.fade_out));

    Gallery gallery = (Gallery) findViewById(R.id.gallery1);
    gallery.setAdapter(new ImageAdapter(this));
    gallery.setOnItemClickListener(new OnItemClickListener() 
    {
        public void onItemClick(AdapterView parent, 
        View v, int position, long id) 
        {                
            imageSwitcher.setImageResource(imageIDs[position]);
        }
    });  
}

 public View makeView() 
{
    ImageView imageView = new ImageView(this);
    imageView.setBackgroundColor(0xFF000000);
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    imageView.setLayoutParams(new 
            ImageSwitcher.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));
    return imageView;
}

public class ImageAdapter extends BaseAdapter 
{
    private Context context;
    private int itemBackground;

    public ImageAdapter(Context c) 
    {
        context = c;

        //---setting the style---                
        TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
        itemBackground = a.getResourceId(
                R.styleable.Gallery1_android_galleryItemBackground, 0);
        a.recycle();                                                    
    }

    //---returns the number of images---
    public int getCount() 
    {
        return imageIDs.length;
    }

    //---returns the ID of an item--- 
    public Object getItem(int position) 
    {
        return position;
    }

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

    //---returns an ImageView view---
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ImageView imageView = new ImageView(context);
        imageView.setImageResource(imageIDs[position]);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));
        imageView.setBackgroundResource(itemBackground);
        return imageView;
    }
   }    
    }
</code></pre>

<p>I have my strings in an array as follows:</p>

<p>arrays.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
&lt;string-array
    name="swan"&gt;
    &lt;item&gt;swan_1&lt;/item&gt;
    &lt;item&gt;swan_2&lt;/item&gt;
    &lt;item&gt;swan_3&lt;/item&gt;
    &lt;item&gt;swan_4&lt;/item&gt;
    &lt;item&gt;swan_5&lt;/item&gt;
    &lt;item&gt;swan_6&lt;/item&gt;
    &lt;item&gt;swan_7&lt;/item&gt;
&lt;/string-array&gt;
&lt;/resources&gt;
</code></pre>

<p>Following the information given to me by Hakan I know what I have to do; I just can't make it work. I have been trying extensively to make this work, but my java knowledge is still too bad. Any further help or would be very welcome indeed, this is causing me a major headache.  </p>

<p>displayview.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;merge xmlns:android="http://schemas.android.com/apk/res/android"&gt;
&lt;ImageSwitcher 
    android:id="@+id/switcher1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"                 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true"      
    /&gt; 
&lt;Gallery
    android:id="@+id/gallery1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"  
    android:layout_marginTop="20dip" 
    /&gt; 
&lt;TextView
    android:id="@+id/textview1"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="10dip"
    android:layout_gravity="center_horizontal|bottom"
    android:background="#AA000000"
    android:textColor="#ffffffff"

    /&gt;
&lt;/merge&gt;
</code></pre>
