Sunday 15 September 2013

java - How to set an image using a hash map -


I want to set an image in a list view using a hash map, all data sets except the image is being done. How do I set an image using hash map? The images are stored in the Painting folder. Below is my code.

  // Make a list of maps & lt; String ,? & Gt; Object Arrestist & lt; Hashmap & lt; String, Object & gt; & Gt; Data = new arreelist & lt; Hashmap & lt; String, Object & gt; & Gt; (); (Attractions attraction: attractions) {Hashmap & lt; String, Object & gt; Map = new hashmop & lt; String, Object & gt; (); Map.put (Attraction_name, attraction .getName ()); Map.put ("img", String.valueOf (R.drawable.king)); Data.add (map); } // create the resource, from, and variable int resource = r. Late Latte_at; String [] from {{charm_name, "img"}; Int [] to = {R.id.name, R.id.img}; // Create and set the adapter simple adapter adapter - new simple adapter (from this, data, resource, with); AttractionListListView.setAdapter (adapter); AttractionListListView.setOnItemClickListener (this); }  

You can use:

In your adapter , Do something like this:

  imageView.setImageResource ((int) Hashmap.Gate ("IMG"));  

However, I really recommend you to do such a thing instead of a Hash Map for a class, in this way you have a list of your class instead of a Hush Map (This is only an internal class that helps you organize). With this, you would want to avoid wearing the Hissapeat material from the intestine.

But secondly, if you really want to use Hashp, then you can use the code written above.

Regards


No comments:

Post a Comment