3
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.offers);
    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
    String xml = XMLfunctions.getX## Heading ##ML();
    Document doc = XMLfunctions.XMLfromString(xml);
    int numResults = XMLfunctions.numResults(doc);
    if((numResults <= 0))
    {
        Toast.makeText(OffersActivity.this, "Geen resultaten gevonden", Toast.LENGTH_LONG).show();  
        finish();
    }
    ImageView newImg = (ImageView) findViewById(R.id.thumbimage);
    NodeList nodes = doc.getElementsByTagName("result");
    for (int i = 0; i < nodes.getLength(); i++)
    {
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element)nodes.item(i);
        map.put("id", XMLfunctions.getValue(e, "id"));
        map.put("name", "" + XMLfunctions.getValue(e, "name"));
        map.put("Score", "" + XMLfunctions.getValue(e, "score"));
        map.put("thumbnail", "" + XMLfunctions.getValue(e, "thumbimg"));
        mylist.add(map);
    }
    ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.listitems, 
            new String[] { "name", "Score",  "thumbnail"}, 
            new int[] { R.id.item_title, R.id.item_subtitle, R.id.thumbimage });
    setListAdapter(adapter);
}

I have addresses of the images which i want to display are in

map.put("thumbnail", "" + XMLfunctions.getValue(e, "thumbimg"));

And i am also getting them. Actually they are coming from live xml. And i want to put them in a image view. Please help!

thanks

dave.c
  • 10,910
  • 5
  • 39
  • 62
Umer Abid
  • 397
  • 1
  • 14
  • Yes this a good article. But in my case xml is on live server. i have get the text and also display it on listview. But not able to display relative images. – Umer Abid Apr 16 '12 at 09:50
  • Check this link : http://www.vogella.com/articles/AndroidListView/article.html.... You will get some idea to solve your problem – Krishna Suthar Apr 16 '12 at 09:54

2 Answers2

2

You need to download the images in the background and then set them in the correct ImageViews.

The adapters don't give you all that functionality by default, so you'll have to do some extra coding yourself.

Take a look at this StackOverflow answer: Lazy load of images in ListView and you'll see what I mean!

Community
  • 1
  • 1
manavo
  • 1,839
  • 2
  • 14
  • 17
  • I am getting this in log 04-16 16:19:46.768: I/System.out(514): resolveUri failed on bad bitmap uri: R.drawable.thmbimg – Umer Abid Apr 16 '12 at 10:24
  • If i had to guess it looks like you're trying to load a local image through the lazyload code? Since it's not a remote image, it won't work in the same way. I think it's trying to parse the R.drawable.thmbimg as a URI and failing (which is normal, since it's not a URI, it's a local android thing). – manavo Apr 16 '12 at 11:37
  • I have done this.. But i got a problem.. Its working perfect in simulator but not in device. I have replace R.drawable.thmbimg with http://cards.designers99.com/thmbimg.png – Umer Abid Apr 16 '12 at 13:19
  • What version of android is each one running? – manavo Apr 16 '12 at 14:31
  • i am doing development in 2.2 and device is 2.3.3. But i have check all API and methods they all supported for both. – Umer Abid Apr 17 '12 at 04:53
1

There is a List view named LazyListview.I think this will help you for sure.This Lazy List will help you to download the images in background.As you open the List Activity intialy you will see the the default image is loaded after downloading the image will be setting one by one which makes an awesome User Interface.

I think this code will help you a lot.... :-)

Sreedev
  • 6,563
  • 5
  • 43
  • 66