我有一个绑定(bind)了自定义适配器的 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, 宽度, 高度,真实));
我可以在上面的 getView() 中使用它来设置 imageView 源。但我想要的是让 ListView 绑定(bind)到适配器而不加载图像(因为这将是繁重的过程)。然后在加载 listView 之后,开始分别绑定(bind)行中的所有 ImageView。他们是实现此目的的方法还是可以将图像下载过程与 listView 绑定(bind)分开的任何方法?
最佳答案
关于android - 列表绑定(bind)后在自定义 ListView 中设置 ImageView 的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23753834/