我看过一个关于如何在列表视图中显示 textview 和 imageview 的示例。这些图像文件位于可绘制文件中。
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};
但我所拥有的是这些图片的外部 url 链接:
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"};
我应该使用什么方法来显示这些图像?