android - How do I get data from HashMap to pass to next Activity? -


i wish pass data 1 listview activity next activity, i.e. when item clicked in list, data such title or thumb_url (an image remote database) can passed detail activity.

in example below, these items set out in hashmap.

what code pass above data activity, using intent?

i'm puzzled because these data items laid out in hashmap.

public class customizedlistview extends activity {     // static variables     static final string url = "http://padihamcars.com/music.xml";     // xml node keys     static final string key_song = "song"; // parent node     static final string key_id = "id";     static final string key_title = "title";     static final string key_artist = "artist";     static final string key_duration = "duration";     static final string key_thumb_url = "thumb_url";      listview list;     lazyadapter adapter;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          final arraylist<hashmap<string, string>> songslist = new arraylist<hashmap<string, string>>();          xmlparser parser = new xmlparser();         string xml = parser.getxmlfromurl(url); // getting xml url         document doc = parser.getdomelement(xml); // getting dom element          nodelist nl = doc.getelementsbytagname(key_song);         // looping through song nodes <song>         (int = 0; < nl.getlength(); i++) {             // creating new hashmap             hashmap<string, string> map = new hashmap<string, string>();             element e = (element) nl.item(i);             // adding each child node hashmap key => value             map.put(key_id, parser.getvalue(e, key_id));             map.put(key_title, parser.getvalue(e, key_title));             map.put(key_artist, parser.getvalue(e, key_artist));             map.put(key_duration, parser.getvalue(e, key_duration));             map.put(key_thumb_url, parser.getvalue(e, key_thumb_url));              // adding hashlist arraylist             songslist.add(map);         }          list=(listview)findviewbyid(r.id.list);          // getting adapter passing xml data arraylist         adapter=new lazyadapter(this, songslist);                 list.setadapter(adapter);          // click event single list row         list.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> parent, view view,                     int position, long id) { } 

try :-

 list.setonitemclicklistener(new onitemclicklistener() {                  @override                 public void onitemclick(adapterview<?> parent, view view,                         int position, long id) {                          hashmap<string, string> map  = songslist.get(position);                         intent intent = new intent(youractivity.this, myotheractivity.class);                         intent.putextra("map", map);                         startactivity(intent);                  } 

and in receiving activity:

protected void oncreate(bundle bundle) {     super.oncreate(savedinstancestate);      intent intent = getintent();     hashmap<string, string> hashmap = (hashmap<string, string>)intent.getserializableextra("map");     log.v("hashmaptest", hashmap.get("key")); } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -