我从在线数据库获取数据并在我的应用上显示它们。我通过JSON获取数据。我有一个图像保存为数据库中的BLOB。我尝试使用此代码将BLOB数据转换为图像并将其显示在页面上,但它不起作用。 (iv
是一个ImageView)
String imgstr = intent.getStringExtra("image");
Log.d("image str from db", "" + imgstr);
if(imgstr!=null){
byte[] b = imgstr.getBytes();
Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
iv.setImageBitmap(bmp);
}else{
iv.setVisibility(View.GONE);
}
我已经在stackoverflow上检查了与此相关的所有答案,但对我没有帮助。所以请不要将问题标记为重复。感谢
更新:添加了我从数据库获取数据的方式.events = json.getJSONArray(TAG_OS); for(int i = 0; i< events.length(); i ++){ JSONObject c = events.getJSONObject(i);
// Storing JSON item in a Variable
String eid = c.getString(TAG_EID);
String ename = c.getString(TAG_ENAME);
String etype = c.getString(TAG_ETYPE);
String edesc = c.getString(TAG_EDESC);
String esdate = c.getString(TAG_ESDATE);
String eedate = c.getString(TAG_EEDATE);
String estime = c.getString(TAG_ESTIME);
String eetime = c.getString(TAG_EETIME);
String location = c.getString(TAG_LOCATION);
String created_at = c.getString(TAG_CREATED_AT);
String edited_at = c.getString(TAG_EDITED_AT);
String createdby = c.getString(TAG_CREATEDBY);
String image= c.getString(TAG_IMAGE);
String approved = c.getString(TAG_APPROVED);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_EID, eid);
map.put(TAG_ENAME, ename);
map.put(TAG_ETYPE, etype);
map.put(TAG_EDESC, edesc);
map.put(TAG_ESDATE, esdate);
map.put(TAG_EEDATE, eedate);
map.put(TAG_ESTIME, estime);
map.put(TAG_EETIME, eetime);
map.put(TAG_LOCATION, location);
map.put(TAG_CREATED_AT, created_at);
map.put(TAG_EDITED_AT, edited_at);
map.put(TAG_CREATEDBY, createdby);
map.put(TAG_IMAGE, image);
map.put(TAG_APPROVED, approved);
oslist.add(map);
list=(ListView)findViewById(R.id.list);
TextView emptyText = (TextView)findViewById(R.id.empty);
list.setEmptyView(emptyText);`
然后从这里单击列表项时,数据将传递到我想要显示图像的当前意图
列出OnItemClick:
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent i = new Intent(ListNew.this, NewEvent.class);
i.putExtra("eid", oslist.get(+position).get("eid") );
//i.putExtra("tel", tels.get(position) );
i.putExtra("ename", oslist.get(+position).get("ename") );
i.putExtra("etype", oslist.get(+position).get("etype") );
i.putExtra("edesc", oslist.get(+position).get("edesc") );
i.putExtra("esdate", oslist.get(+position).get("esdate") );
i.putExtra("eedate", oslist.get(+position).get("eedate") );
i.putExtra("estime", oslist.get(+position).get("estime") );
i.putExtra("eetime", oslist.get(+position).get("eetime") );
i.putExtra("location", oslist.get(+position).get("location") );
i.putExtra("created_at", oslist.get(+position).get("created_at") );
i.putExtra("edited_at", oslist.get(+position).get("edited_at") );
i.putExtra("createdby", oslist.get(+position).get("createdby") );
i.putExtra("image", oslist.get(+position).get("image") );
i.putExtra("approved", oslist.get(+position).get("approved") );
startActivity(i);
}
});