Question

        try
        {
            if(json.getString(KEY_SUCESS)!=null)
            {
                String res=json.getString(KEY_SUCESS);
                if(Integer.parseInt(res)==1)
                {
                    JSONObject json_user = json.getJSONObject("user");
                    name=json_user.getString(KEY_NAME);

                    String image=json_user.getString(KEY_PHOTO);

                    map.put(KEY_NAME, name);

                    map.put(KEY_PHOTO, image);

                    List.add(map);


                }
            }

The photo is an String which is encoded in base64 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 ImageView?

Was it helpful?

Solution

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.

imageView.setImageBitmap(bitmap);

OTHER TIPS

Update the adapter that your listview uses with a new entry for the string you needed to decode.

Then call notifyDataSetChanged() from your adapter after you've updated the data in it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top