Skip to content Skip to sidebar Skip to footer

Different Text For Each Image In Image Viewpager

I used viewpager class to display sets of images instead of gallery class as its deprecated and customized it to show the text by using the below code , the problem is the same tex

Solution 1:

You could pass an array of Strings into your adapter that correspond to each image.. ex.

In the activity declare your string array with your list of images..

privateint imageArra[] = { R.drawable.a, R.drawable.b, R.drawable.c,
                              R.drawable.d, R.drawable.e};  

privateString[] stringArray = newString[] { "Image a", "Image b","Image c","Image d","Image e"}; 

Then when instantiating your adapter..

ImagePagerAdapteradapter=newImagePagerAdapter(this, imageArra, stringArray );

In your adapter:

int imageArray[];
String[] stringArray;
public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) {
    imageArray = imgArra;
    activity = act;
    stringArray = stringArra;
}

Then assign the text value from the array

TextView txt=(TextView) layout.findViewById(R.id.image_text);
txt.setText(stringArray[position]);

Post a Comment for "Different Text For Each Image In Image Viewpager"