开发者

Add description to custom gallery view in android

do anyone know how to add the name of image or a description of the image so that it will also get change on flinging of every image.

i am able to do it by taking a separate text view and inflating this text view in the getView() of the adapter. But its not efficient . so please help me to find out the other way...

my code:

**public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;
    private Vector<ListObjectWithTwoTextAndOneImage> data;
    public ImageAdapter(Context c,
            Vector<ListObjectWithTwoTextAndOneImage> d)
{
    super();
        mContext = c;
        data = d;

    }
    public int g开发者_如何学GoetCount() {
        return data.size();
    }
    public Object getItem(int position) {
        return position;
    }
    public long getItemId(int position) {
        **fishName.setText(data.get(position).getFirstItem());**
        return position;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);

        imageView.setImageBitmap((Utils.getInstance().getImageFromAssets(
                PhotoGalleryGallery.this, data.get(position)
                        .getThumbNailImageUrl() + ".jpg"))); // TODO: change
        imageView.setLayoutParams(new Gallery.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        // imageView.setBackgroundResource(mGalleryItemBackground);
        return imageView;
    }
}**

thanks in advance


thanks ...i got the other alternate solution also.. I have just created one Linear layout inside the get dynamically and then adding one image and text view,....

public View getView(int position, View convertView, ViewGroup parent) {

        LinearLayout layout = new LinearLayout(getApplicationContext());
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setLayoutParams(new Gallery.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));


        ImageView imageView = new ImageView(mContext);
        imageView.setImageBitmap((Utils.getInstance().getImageFromAssets(
                PhotoGalleryGallery.this, data.get(position)
                        .getThumbNailImageUrl() + ".jpg"))); // TODO: change

        if (Configuration.ORIENTATION_PORTRAIT==PhotoGalleryGallery.this.getResources().getConfiguration().orientation) {

            imageView.setLayoutParams(new Gallery.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);

            TextView tv = new TextView(mContext);
            tv.setText(data.get(position).getFirstItem());
            tv.setTextColor(Color.WHITE);
            tv.setTypeface(null, Typeface.BOLD);
            tv.setPadding(20, 20, 0, 5);
            tv.setMaxLines(2);
            tv.setMinLines(2);

            ImageView divider= new ImageView(mContext);
            divider.setBackgroundResource(R.drawable.devider);
            divider.setLayoutParams(new Gallery.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            divider.setScaleType(ImageView.ScaleType.FIT_XY);

            TextView tv1 = new TextView(mContext);
            tv1.setText(data.get(position).getSecondItem());
            tv1.setTextColor(Color.WHITE);
            tv1.setTypeface(null, Typeface.BOLD);
            tv1.setPadding(20, 5, 0, 0);
            tv1.setMinLines(2);
            tv1.setMaxLines(2);

            layout.addView(imageView);
            layout.addView(tv);
            layout.addView(divider);
            layout.addView(tv1);

        } else {
            imageView.setLayoutParams(new Gallery.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            layout.addView(imageView);

        }
        picPosition=position;

        return layout;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜