Android Studio base64 image to ListView -
i'm trying listview base64 images. listviews data json-array server , created hashmap.
jsonobject c = products.getjsonobject(i); // storing each json item in variable string id = c.getstring("pid"); string createdat = c.getstring("created_at"); string description = c.getstring("description"); string image = c.getstring("image"); // creating new hashmap hashmap<string, string> map = new hashmap<string, string>(); // adding each child node hashmap key => value map.put("pid", id); map.put("description", description); map.put("image", image); // adding hashlist arraylist productslist.add(map); }
and:
protected void onpostexecute(string file_url) { // updating ui background thread runonuithread(new runnable() { public void run() { /*updating parsed json data listview*/ listadapter adapter = new simpleadapter( listactivity.this, productslist, r.layout.list_item, new string[] { "product_id", "product_description", "product_image" }, new int[] { r.id.pid, r.id.description, r.id.image }); // updating listview setlistadapter(adapter); } }); }
how can make image string converted imageview? i'm new android studio, don't know if thats smart way that..
above code from: http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ if helps.
first have convert base64 bitmap, , can set on imageview.
how decode base64 bitmap:
byte[] decodedstring = base64.decode(encodedimage, base64.default); bitmap decodedbyte = bitmapfactory.decodebytearray(decodedstring, 0, decodedstring.length);
how set bitmap imageview:
imageview mimg = (imageview) findviewbyid(r.id.(your xml img id)); mimg.setimagebitmap(decodedbyte );
Comments
Post a Comment