joshapoorva joshapoorva - 1 year ago 119
Android Question

Android Listview and image decoding

String res=json.getString(KEY_SUCESS);
JSONObject json_user = json.getJSONObject("user");

String image=json_user.getString(KEY_PHOTO);

map.put(KEY_NAME, name);

map.put(KEY_PHOTO, image);



The photo is an String which is encoded in
and i want to decode it and add to the map created but it take two string value and if i create a new map it would not add to that list view that i have created ,
what i have to do is to decode the string image to set it to a

Answer Source

You don't show where your map is defined, but you get to choose what type of objects its key/value pair is.

It sounds like you want to take the string, decode into a bitmap and then store that into the map.

Define the map this way:

Map map = new HashMap<String, Bitmap>();

and then save it this way:

String image=json_user.getString(KEY_PHOTO);
byte[] decodedString = Base64.decode(image, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
map.put(KEY_PHOTO, bitmap);

And if you want to set the bitmap to an ImageView, you do the following.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download