![](/img/trans.png)
[英]Displaying ParseFile Containing Images Using Their Urls In A RecyclerView
[英]Displaying multiple images using their URLs to listview with JSON
我一直在尝试将我的图片网址加载到第一个必须下载的列表视图中,有人可以帮助我。
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", String.valueOf(i));
map.put("name", "House name:" + json_data.getString("name"));
map.put("address", "Adress: " + json_data.getString("address"));
URL newurl = new URL(json_data.getString("imageUrl"));
itmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(result).getContent());
ImageView imagy = (ImageView)findViewById(R.id.image);
imagy.setImageBitmap(bitmap);
map.put("img",bitmap);//error is here says convert bitmap to type string
mylist.add(map);
你正在用这段代码做什么?
URL newurl = new URL(json_data.getString("imageUrl"));
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(result).getContent());
ImageView imagy = (ImageView)findViewById(R.id.image);
imagy.setImageBitmap(bitmap);
map.put("img",bitmap);//error is here says convert bitmap to type string
mylist.add(map);
因为您每次都在执行findViewById()并设置图像位图。 然后你添加了mylist。
建议:相反,我建议你只在HashMap中添加URL字符串:
String strImageURL = json_data.getString("imageUrl");
map.put("img",strImageURL );/
在为ListView定义自定义适配器时,只需按照自定义适配器的getView()方法(可以通过扩展BaseAdapter定义)进行操作。
建议2:如果你想在ListView中实现延迟加载图像,那么请查看Fedor在这里给出的答案: Android - 如何在ListView中执行延迟加载的图像
我希望,你实际的HashMasp是HashMap map = new HashMap();
如果是这样,你只能添加字符串值。 试试以下,
class House {
int id;
String houseName;
String houseAddress;
Bitmap image;
}
List<House> houseList = new ArrayList<House> ();
House houseObj = new House();
houseObj.id = i;
houseObj.houseName = "House name:" + json_data.getString("name");
houseObj.address = "Adress: " + json_data.getString("address");
URL newurl = new URL(json_data.getString("imageUrl"));
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(result).getContent());
ImageView imagy = (ImageView)findViewById(R.id.image);
imagy.setImageBitmap(bitmap);
houseObj.image = bitmap;
houseList.add(houseObj);
在你的listview适配器中使用此列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.