0

I need to display a list of options in my listview (or suitable alternative), retrieved from a json feed. I have this working. I have also been able to process image urls to a drawable, from the json using dhuckabys prime image loader (https://github.com/DHuckaby/Prime).

I can display a list of text by making a string array and passing it into the adapter, I just can't figure out a way to display my drawables in the list. All examples I've found show how to use icons from the drawables folder.

Ideally, I want to interate through my json, process the image urls and add the drawable and the title so that it can be shown in a list.

I've tried making custom list adapters without success.

Any help or links to relavant tutorials would be helpful. I can only find tutorials that use local drawables.

Thanks.

SteveEdson
  • 2,485
  • 2
  • 28
  • 46
  • http://stackoverflow.com/questions/5442712/dynamically-create-draw-images-to-put-in-android-view – jos Aug 15 '12 at 13:56

3 Answers3

1

First create a custom xml to inflate your listView . In this xml add a imageview . THen after you get the URL of the image you can do something like this

  ImageView image = (ImageView) v.findViewById(R.id.avatar);

   image.setImageBitmap(getBitmap(image_url));

  public Bitmap getBitmap(String bitmapUrl) 
           {
               try  
               {
                 URL url = new URL(bitmapUrl);
                 return BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
                }
                catch(Exception ex) {return null;}
}

Do this recursively or once according to your need . Also sorry for not posting the full code but this should help you understand what you need to do.

Android2390
  • 1,150
  • 12
  • 21
0

you can get the image from a url using this code

URL url = new URL(imageUrl);
HttpURLConnection connection  = (HttpURLConnection) url.openConnection();

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is);  

you can use the bitmap obj to set the image to your listview Hope this is what you need

G_S
  • 7,068
  • 2
  • 21
  • 51
  • 1
    Thanks for your reply, I'm able to get the image from the url, I just don't know how to add the retrieved image to a listview. – SteveEdson Aug 15 '12 at 14:19
  • You are having the custom List view. in the custom ListView use image view and set the bitmap image over there like ImgView.setImageBitmap(img); To use imageViews in the custom List view Check this http://codinglookseasy.blogspot.in/2012/07/custom-list-view.html – G_S Aug 15 '12 at 15:12
0

and if you want to download asynchronously to avoid lags have a look at this library: https://github.com/nostra13/Android-Universal-Image-Loader

vallllll
  • 2,731
  • 6
  • 43
  • 77