0

I've seen an example about how to show textview and imageview in an listview. These image files are in drawable file.

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

                if(convertView==null){   
                    convertView=LayoutInflater.from(mContext).inflate(R.layout.item, null);   
                    ItemViewCache viewCache=new ItemViewCache();   
                    viewCache.mTextView=(TextView)convertView.findViewById(R.id.text); 
                    viewCache.mTextView1=(TextView)convertView.findViewById(R.id.text1);
                    viewCache.mImageView=(ImageView)convertView.findViewById(R.id.image);   
                    convertView.setTag(viewCache);   
                }   
                ItemViewCache cache=(ItemViewCache)convertView.getTag();   

                cache.mTextView.setText(texts[position]);  
                cache.mTextView1.setText(texts1[position]);
                cache.mImageView.setImageResource(images[position]);
                return convertView;   
            }   
        }   
                    private static class ItemViewCache{   
            public TextView mTextView;  
            public TextView mTextView1;
            public ImageView mImageView;   
        }   

        private  String[] texts=new String[]{"one","two","three"}; 
        private  String[] texts1=new String[]{"wether","tuan","background"};
        private int[] images=new int[]{R.drawable.img1,R.drawable.img2,R.drawable.img3};

But what I have is the external url links of these images:

private String[] images=new String[]{"http://ia.media-imdb.com/images/M/MV5BMjMyOTM4MDMxNV5BMl5BanBnXkFtZTcwNjIyNzExOA@@._V1._SX54_CR0,0,54,74_.jpg",
                "http://i.media-imdb.com/images/SF1f0a42ee1aa08d477a576fbbf7562eed/realm/feature.gif",
                "http://ia.media-imdb.com/images/M/MV5BMzk3MTE5MDU5NV5BMl5BanBnXkFtZTYwMjY3NTY3._V1._SX54_CR0,0,54,74_.jpg"};

What method should I use to show these images?

user23256
  • 53
  • 2
  • 9

2 Answers2

1

You can load the images using steve's code from How to load an ImageView by URL in Android?

Now you have two options:

1) Use a custom listview (where you create an xml file displaying an imageview, textview, and possibly other items you need for each row in your list)

2) Use the standard listview which contains just a TextView (which has a CompoundDrawable which allows you to position the image to the left/right/top/below the text)

1) Custom List View

Create an xml resource for your row layout which contains a textview and an imageview (and possibly other items) then display it in your list view calling setImageBitmap on the ImageView. For details on creating a custom listview, see the tutorial at http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

2) Standard Listview

Call setCompoundDrawableWithIntrinsicBounds on the default textview to set the appropriate Drawable for your image. To convert your bitmap to a drawable, see How to convert a Bitmap to Drawable in android?

Community
  • 1
  • 1
Adrian G
  • 775
  • 6
  • 11
0

google has a pretty good example (including code) of how to show images from the web :

http://developer.android.com/training/displaying-bitmaps/index.html

android developer
  • 114,585
  • 152
  • 739
  • 1,270