我有一个ListView与自定义适配器绑定,并且可以正常工作:
private class Placeslist extends ArrayAdapter<ArrayList<String>> {
private ArrayList<ArrayList<String>> items;
public Placeslist(Context context, int textViewResourceId,
ArrayList<ArrayList<String>> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.locationgpsrow, null);
}
ArrayList<String> o = items.get(position);
if (o != null) {
// Binding here
TextView tv1 = (TextView) v.findViewById(R.id.txt1);
tv1.setText(o.get(0));
ImageView imView = (ImageView) v.findViewById(R.id.imageView1);
//o.get(1) // Image url e.g. http://www.some-website/image.jpg
}
return v;
}
}
我在一个数组元素中有一个图像源URL,我需要下载图像并将其设置为listview项目自定义布局中的ImageView。而且,我也有代码!!
ImageView imView = (ImageView) findViewById(R.id.imageView1);
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
is.close();
imView.setImageBitmap(Bitmap.createScaledBitmap(bmImg,width,
高度,真));
我可以在上面的getView()中使用它来设置imageView源。但是我想要的是让列表视图绑定到适配器而不加载图像(因为这将是繁重的过程)。然后在加载listView之后,分别开始绑定行中的所有ImageView。他们是实现此目的的一种方法,还是可以将图像下载过程与listView绑定分开的任何方法?
最佳答案
您必须使用以下lib来在运行时加载图像:-
Universal loader lib
Picasso
Urlhelper