0

I have been trying to load my image urls onto a listview that is the first have to be downloaded can someone please help me.

HashMap<String, String> map = new HashMap<String, String>();
 map.put("id", String.valueOf(i));
 map.put("name", "House name:" + json_data.getString("name"));
map.put("address", "Adress: " + json_data.getString("address"));

URL newurl = new URL(json_data.getString("imageUrl"));
 itmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(result).getContent());
 ImageView imagy = (ImageView)findViewById(R.id.image);
 imagy.setImageBitmap(bitmap); 
  map.put("img",bitmap);//error is here says convert bitmap to type string
  mylist.add(map);
Rajesh Satvara
  • 3,842
  • 2
  • 30
  • 50
user1207576
  • 17
  • 1
  • 7

2 Answers2

1

What are you doing exactly with this code?

 URL newurl = new URL(json_data.getString("imageUrl"));
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(result).getContent());
            ImageView imagy = (ImageView)findViewById(R.id.image);
              imagy.setImageBitmap(bitmap); 
             map.put("img",bitmap);//error is here says convert bitmap to type string

            mylist.add(map);

Because you are doing findViewById() and setting image bitmap every time. And then you are adding in mylist.

Suggestion: Instead i would suggest you to add only URL string into HashMap:

String strImageURL = json_data.getString("imageUrl");
map.put("img",strImageURL );/

And while defining Custom adapter for your ListView, just do as you are doing above inside the getView() method of your custom adapter (which you can define by extending BaseAdapter).

Suggestion 2: If you want to implement Lazy loading of images inside ListView, then check Fedor's answer given here: Android - How do I do a lazy load of images in ListView

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • The problem is Fedor's only dealing with static images and mine are dynamic.His mstrings(the static list) when i replace with my imageUrl[i] (my fetch from json)doesn't work and associating each detail with the image also i'm having a problem with. – user1207576 Mar 08 '12 at 11:39
  • he he he....instead you can also pass your Array to the custom adapter. You just need to look at the example and ImageLoader class usage. – Paresh Mayani Mar 08 '12 at 12:55
1

I hope, ur actual HashMasp is HashMap map = new HashMap ();

if so, u can only add String values. try the following,

class House {
    int id;
    String houseName;
    String houseAddress;
    Bitmap image;
}

List<House> houseList = new ArrayList<House> ();

House houseObj = new House();

houseObj.id = i;
houseObj.houseName = "House name:" + json_data.getString("name");
houseObj.address = "Adress: " + json_data.getString("address");

URL newurl = new URL(json_data.getString("imageUrl"));
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(result).getContent());
ImageView imagy = (ImageView)findViewById(R.id.image);
imagy.setImageBitmap(bitmap); 

houseObj.image = bitmap;

houseList.add(houseObj);

use this list in ur listview adapter.

Jayabal
  • 3,619
  • 3
  • 24
  • 32