【发布时间】:2013-12-13 19:50:05
【问题描述】:
我想在简单的列表视图中显示图像,
我们有 arraylist HashMap,其中包含城市、描述等值。
& 我们必须转换为图像并设置到 ListView 和 List 行 xml 的每一行的 base64 图像字符串是listview_row.xml
这是我在列表视图中显示文本字段的代码,完成:
ArrayList<HashMap<String, String>> arllist = new ArrayList<HashMap<String, String>>();
Intent intent = getIntent();
arllist = (ArrayList<HashMap<String, String>>) intent.getSerializableExtra("map");
int length = arllist.size();
for(int i=0; i<length; i++)
{
try{
String stringToConvert = arllist.get(i).get("image");
byte[] decodedString = Base64.decode(stringToConvert, Base64.NO_PADDING);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
ImageView image = (ImageView)this.findViewById(R.id.img);
image.setImageBitmap(decodedByte);
}
catch (Exception e) {
// TODO: handle exception
Toast.makeText(productlist.this, e.toString(), Toast.LENGTH_LONG).show();
}
}
SimpleAdapter listadapter = new SimpleAdapter(this, arllist, R.layout.list_item,
new String[] {"city", "category", "description", "mobile", "landmark"},
new int[] {R.id.city, R.id.category, R.id.desc, R.id.mobile, R.id.landmark});
ListView list=(ListView)findViewById(R.id.list);
list.setAdapter(listadapter);
我的问题是如何将图像转换并绑定到适配器以将其显示在列表视图的每一行 并且在转换图像时也会出错---bad base64
【问题讨论】:
标签: java android listview android-listview