开发者

In gridview , i want to set an image and a name to that image?

I successfully set the image from the adapter. I want to set the name below the image. How to do this. The names are stored in a string array. The code snippet from the adapter is as below.

if (convertView == null) {  // if it's not recycled, initialise some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 6 , 4 ,2);

        } else {
            i开发者_Python百科mageView = (ImageView) convertView;
        }

also i want the images and the image title to be as close as in the image in the link below.

How to implement custom device photos gallery for android?

Thank you.


Better you can create a new layout where you have a ImageView and TextView in Linear layout.( TextView is kept under ImageView).

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

            View view = getLayoutInflater().inflate(R.layout.gridview_layout,
                    null);//gridview_layout is the layout tht you have created.
            TextView textView = (TextView) view.findViewById(R.id.Sample);//Sample is the textView id
            ImageView imageView = (ImageView) view.findViewById(R.id.sampleim);//sampleim is the imageview id
            textView.setText(names[position]);//names:your string array of names
            imageView.setImageResource(imageids[position]);//imageids: String array of images.
            view.setLayoutParams(new GridView.LayoutParams(200, 200));
            return view;
        }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜