0

I'm using photo gallery in my project and I can inflate image into gallery with my adapter. If I want to add text (2-3 words as name of image) on bottom of image what should I do? Is there ny reference abut it?

Thanks so much.

Hesam
  • 52,260
  • 74
  • 224
  • 365
  • When you return a image view probably you can use some external Jars to modify the image. Try your luck. [Read this similar question](https://stackoverflow.com/questions/5459701/how-can-i-watermark-an-image-in-java). – Jay Mayu Apr 25 '12 at 12:50

2 Answers2

1

Create and return a custom view object from the getView method of your adapter. You could inflate an XML containing an ImageView and a TextView inside a LinearLayout having vertical orientation.

Rajesh
  • 15,724
  • 7
  • 46
  • 95
0

FIRST : create gallery_items layout which has textview and imageview ,

then you have to inflate the layout in getView method with use of ViewHolder class ,

as below :

 public class GalleryPhotoWithText extends Activity {
  private  Gallery galleryView; 
    /** Called when the activity is first created. */
    @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

      galleryView = (Gallery)findViewById(R.id.galleryid);

       galleryView.setAdapter(new ImageAdapter(this));         
           }


 public class ImageAdapter extends BaseAdapter { 
  private Activity activity;  
  private  LayoutInflater inflater=null; 
  public ImageAdapter(Activity a) {   
      activity = a;  
           inflater = (LayoutInflater)activity.getSystemService
                   (Context.LAYOUT_INFLATER_SERVICE);          } 

 public int getCount() {   
    return data.length;         }  

public Object getItem(int position) {   
    return position;         }   

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

public  class ViewHolder{   
    public TextView text;    
    public ImageView image;         }   

public View getView(int position, View convertView, ViewGroup parent) {   
    View vi=convertView;   
    ViewHolder holder;   
    if(convertView==null){  
        vi = inflater.inflate(R.layout.gallery_items, null); 
        holder=new ViewHolder();  
        holder.text=(TextView)vi.findViewById(R.id.textView1);  
        holder.image=(ImageView)vi.findViewById(R.id.image);   
        vi.setTag(holder);             }  

        else    

    holder=(ViewHolder)vi.getTag();  
    holder.text.setText(name[position]); 
    final int stub_id=data[position];  
    holder.image.setImageResource(stub_id);  
    return vi;         } 

    private int[] data = {  
        R.drawable.image1, R.drawable.image2,  
        R.drawable.image3, R.drawable.image4,  


                        };  
    private String[] name = {  
        "first pic name", "second pic name",  
        "third pic name", "fourth pic name",  



        };     } }

Hope this help

Android Stack
  • 4,314
  • 6
  • 31
  • 49