我想在简单的列表视图中显示图像,
我们有arraylist HashMap ,其中包含城市,描述等值。
&安培;我们必须转换为图像并设置为ListView和List行xml的每一行的base64图像字符串是listview_row.xml
这是我在listview中显示文本字段的代码,完成了:
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
答案 0 :(得分:0)
答案 1 :(得分:0)
要转换Base64字符串,请尝试此操作 -
假设您的图像数据是名为myImageData的字符串:
byte[] imageAsBytes = Base64.decode(myImageData.getBytes());
ImageView image = (ImageView)this.findViewById(R.id.ImageView);
image.setImageBitmap(
BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
);