Anybody know how to add text for each image?
Thanks

On Nov 20, 4:14 pm, "pramod.deore" <[email protected]> wrote:
> I have 2 xml files as
> 1)icon.xml
>
> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/android";
> android:id="@+id/widget44"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:orientation="vertical"
> android:layout_x="201px"
> android:layout_y="165px"
> android:gravity="center_horizontal">
> <ImageView
> android:id="@+id/icon_image"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content">
> </ImageView>
> <TextView
> android:id="@+id/icon_text"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:text="TextView"
> android:gravity="center_horizontal"
> android:textColorHighlight="#656565">
> </TextView>
> </LinearLayout>
>
> 2) displayview.xml
> <?xml version="1.0" encoding="utf-8"?>
> <GridView xmlns:android="http://schemas.android.com/apk/res/android";
>     android:id="@+id/gridview"
>     android:layout_width="fill_parent"
>     android:layout_height="fill_parent"
>     android:numColumns="auto_fit"
>     android:verticalSpacing="10dp"
>     android:horizontalSpacing="10dp"
>     android:columnWidth="90dp"
>     android:stretchMode="columnWidth"
>     android:gravity="center"
> />
>
> On Nov 20, 2:17 pm, "pramod.deore" <[email protected]> wrote:
>
> > I want to display image and text below that image in GridView format.
> > I had written some code after searching. But I don't know how to add
> > text below these images. And how to get name of that image name? Using
> > this code I can get index of images.
>
> > public class GridViewExample extends Activity
> > {
> >          Integer[] imageIDs = {
> >                     R.drawable.pic1,
> >                     R.drawable.pic2,
> >                     R.drawable.pic3,
> >                     R.drawable.pic4,
> >                     R.drawable.pic5,
> >                     R.drawable.pic6,
> >                     R.drawable.pic7
> >             };
>
> >             @Override
> >             public void onCreate(Bundle savedInstanceState)
> >             {
> >                 super.onCreate(savedInstanceState);
> >                 setContentView(R.layout.displayview);
>
> >                 GridView gridView = (GridView) findViewById(R.id.gridview);
> >                 gridView.setAdapter(new ImageAdapter(this));
>
> >                 gridView.setOnItemClickListener(new OnItemClickListener()
> >                 {
> >                     public void onItemClick(AdapterView parent,
> >                     View v, int position, long id)
> >                     {
> >                         Toast.makeText(getBaseContext(),
> >                                 "pic" + (position + 1) + " selected",
> >                                 Toast.LENGTH_SHORT).show();
> >                     }
> >                 });
> >             }
>
> >             public class ImageAdapter extends BaseAdapter
> >             {
> >                 private Context context;
>
> >                 public ImageAdapter(Context c)
> >                 {
> >                     context = c;
> >                 }
>
> >                 //---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;
> >                     if (convertView == null) {
> >                         imageView = new ImageView(context);
> >                         imageView.setLayoutParams(new
> > GridView.LayoutParams(85, 85));
>
> > imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
> >                         imageView.setPadding(5, 5, 5, 5);
> >                     } else {
> >                         imageView = (ImageView) convertView;
> >                     }
> >                     imageView.setImageResource(imageIDs[position]);
> >                     return imageView;
> >                 }
> >             }
>
> > }
>
>

-- 
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

Reply via email to