[英]How could I use setViewImage in SimpleAdapter?
I will build a listview with images from the web. 我将使用网络图像构建一个列表视图。 I've also asked an other question before: Android ListView with images from special hashmap .
之前我也问过另一个问题: Android ListView带有来自特殊hashmap的图像 。 But now I tried to extend the SimpleAdapter.
但是现在我尝试扩展SimpleAdapter。 I use a hashmap to put the data.
我使用哈希图来放置数据。 Then I use a new "ImageAdapter":
然后,我使用一个新的“ ImageAdapter”:
public class ImageAdapter extends SimpleAdapter {
public ImageAdapter(Context context,
List<? extends Map<String, ?>> data, int resource, String[] from,
int[] to) {
super(context, data, resource, from, to);
// TODO Auto-generated constructor stub
}
@Override
public void setViewImage(ImageView v, String value) {
super.setViewImage(v, value);
URL url;
try {
url = new URL(value);
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
Bitmap bm = BitmapFactory.decodeStream(is);
v.setImageBitmap(bm);
} catch (Exception e) {
e.printStackTrace();
}
}
}
My list.xml: 我的list.xml:
[...]
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip" />
[...]
There is no error - but the imageview is blank / white! 没有错误-但是imageview是空白/白色! How could I fill the imageview with the image defined in data (as String / URL):
如何用数据中定义的图像(如String / URL)填充imageview:
ada = new ImageAdapter(getApplicationContext(), data, R.layout.list, new String[] {"imgurl", "title", "date", "ex", "id"}, new int[] {R.id.list_image, android.R.id.text1, android.R.id.text2, R.id.text3});
Thanks for helping! 感谢您的帮助! I tried many variations...but nothing works :(
我尝试了许多变化...但没有任何效果:(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.