xml - Android - Multilevel Listviews -


i relatively new android , working online api. have 2 activities. first activity bringing list of search results , placing them listview. not problem. trying select item listview , pass next activity , fill listview in new activity information selected item. problem is. second activity never loads. way second activity work? have been doing research , not getting desired results. code 2 activities , helper class below. thank you

the first activity

import helper.artistcalendarhelper;  import java.util.arraylist; import java.util.hashmap; import java.util.list;  import org.w3c.dom.document; import org.w3c.dom.element; import org.w3c.dom.nodelist;  import services.xmlparser;  import android.app.listactivity; import android.app.progressdialog; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.adapterview; import android.widget.listadapter; import android.widget.listview; import android.widget.simpleadapter; import android.widget.textview; import android.widget.adapterview.onitemclicklistener;  public class artistssearchactivity extends listactivity {  public static final string tag = "artistssearchactivity"; public static final string intent_extras_xml = "xml";  static final string key_artists = "artist"; static final string key_id = "id"; static final string key_display_name = "displayname"; static final string key_uri = "uri"; static final string key_on_tour_until = "ontouruntil"; string ontouruntil ; string displayname; string identification;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_artists_search);      string xml = getintent().getstringextra(homeactivity.intent_extras_xml);      list<hashmap<string, string>> menuitems = new arraylist<hashmap<string, string>>();      addartiststohashmap(menuitems, xml);     additemstolist(menuitems); }  private void additemstolist(list<hashmap<string, string>> menuitems) {     listadapter adapter = new simpleadapter(this, menuitems,             r.layout.list_item_artist_search, new string[] { key_id, key_display_name,                     key_uri, key_on_tour_until }, new int[] { r.id.tvid,                     r.id.tvdisplayname, r.id.tvuri, r.id.tvontouruntil });      setlistadapter(adapter); }  private void addartiststohashmap(list<hashmap<string, string>> menuitems,         string xml) {     xmlparser parser = new xmlparser();      document doc = parser.getdomelement(xml);      nodelist nl = doc.getelementsbytagname(key_artists);     (int = 0; < nl.getlength(); i++) {         hashmap<string, string> map = new hashmap<string, string>();         element e = (element) nl.item(i);          map.put(key_id, e.getattribute(key_id));         map.put(key_display_name, e.getattribute(key_display_name));         map.put(key_uri, e.getattribute(key_uri));         map.put(key_on_tour_until, e.getattribute(key_on_tour_until));          menuitems.add(map);     }  // selecting single listview item         listview lv = getlistview();          lv.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> parent, view view,                     int position, long id) {                 // getting values selected listitem                 displayname = ((textview) view.findviewbyid(r.id.tvdisplayname)).gettext().tostring();                 ontouruntil = ((textview) view.findviewbyid(r.id.tvontouruntil)).gettext().tostring();                 identification = ((textview) view.findviewbyid(r.id.tvid)).gettext().tostring();                  new asyncdownload().execute(identification);             }         }); }  private class asyncdownload extends asynctask<string, string, string> {      progressdialog pdialog;      @override     protected void onpreexecute() {         super.onpreexecute();         pdialog = new progressdialog(artistssearchactivity.this);         pdialog.setmessage("please wait...");          pdialog.setcancelable(false);         pdialog.show();     }      @override     protected string doinbackground(string... params) {          log.v(tag, "query is" +  params[0]);         string result = new artistcalendarhelper().getxml(params[0]);         return result;     }      @override     protected void oncancelled() {         super.oncancelled();         pdialog.dismiss();     }      @override     protected void onpostexecute(string result) {         super.onpostexecute(result);         pdialog.dismiss();         log.v(tag, "result=" + result);         intent intent = new intent();         intent.setclass(artistssearchactivity.this, singleartistactivity.class);         intent.putextra(key_display_name, displayname);         intent.putextra(key_id, identification);         intent.putextra(key_on_tour_until, ontouruntil);         intent.putextra(intent_extras_xml, result);         startactivity(intent);     } } } 

the second activity

import java.util.arraylist; import java.util.hashmap; import java.util.list;  import org.w3c.dom.document; import org.w3c.dom.element; import org.w3c.dom.nodelist;  import services.xmlparser;  import android.os.bundle; import android.app.activity; import android.app.listactivity; import android.content.intent; import android.widget.listadapter; import android.widget.simpleadapter; import android.widget.textview;   public class singleartistactivity extends listactivity {  public static final string tag = "singleartistactivity"; public static final string intent_extras_xml = "xml";  static final string key_venue = "event"; static final string key_venue_name = "displayname";      static final string key_display_name = "displayname";     static final string key_on_tour_until = "ontouruntil";     static final string key_id = "id";      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_single_artist);          // getting intent data         intent in = getintent();          // xml values previous intent         string displayname = in.getstringextra(key_display_name);         string ontouruntil = in.getstringextra(key_on_tour_until);         string id = in.getstringextra(key_id);          // displaying values on screen         textview lbldisplayname = (textview) findviewbyid(r.id.display_name_label);         textview lblontouruntil = (textview) findviewbyid(r.id.on_tour_until_label);         textview lblid = (textview) findviewbyid(r.id.id_label);          lbldisplayname.settext(displayname);         lblontouruntil.settext(ontouruntil);         lblid.settext(id);          string xml = getintent().getstringextra(homeactivity.intent_extras_xml);          list<hashmap<string, string>> menuitems = new arraylist<hashmap<string, string>>();           additemstolist(menuitems);            addcalendartohashmap(menuitems, xml);     }      private void additemstolist(list<hashmap<string, string>> menuitems) {         listadapter adapter = new simpleadapter(this, menuitems,                 r.layout.list_item_artist_calendar, new string[] { key_venue_name }, new int[] { r.id.calendardisplayname });          setlistadapter(adapter);     }      private void addcalendartohashmap(list<hashmap<string, string>> menuitems,             string xml) {         xmlparser parser = new xmlparser();          document doc = parser.getdomelement(xml);          nodelist nl = doc.getelementsbytagname(key_venue);         (int = 0; < nl.getlength(); i++) {             hashmap<string, string> map = new hashmap<string, string>();             element e = (element) nl.item(i);              map.put(key_venue_name, e.getattribute(key_venue_name));              menuitems.add(map);         }     } } 

and helper class

import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.io.unsupportedencodingexception; import java.net.urlencoder;  import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.client.httpclient; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.defaulthttpclient;  import android.util.log;  public class locationcalendarhelper { private static final string tag = "locationcalendarhelper"; private static final string songkick_url = "http://api.songkick.com/api/3.0/metro_areas/"; private static final string api_key = "yiekmi1hqzcfhekc";  public string getxml(string searchquery) {      httpclient httpclient = new defaulthttpclient();      string getparameters = "";     try {         getparameters =  urlencoder.encode(searchquery, "utf-8")                 + "/calendar.xml?apikey=" + urlencoder.encode(api_key, "utf-8");     } catch (unsupportedencodingexception e1) {         // todo auto-generated catch block         e1.printstacktrace();     }      string url = songkick_url + getparameters;     // prepare request object     httpget httpget = new httpget(url);      // execute request     httpresponse response;     try {         response = httpclient.execute(httpget);         // examine response status         log.i(tag, response.getstatusline().tostring());          // hold of response entity         httpentity entity = response.getentity();         // if response not enclose entity, there no need         // worry connection release          if (entity != null) {              // simple json response read             inputstream instream = entity.getcontent();             string result = convertstreamtostring(instream);              // have string representation of html request             instream.close();             return result;         }      } catch (exception e) {          e.printstacktrace();         return null;     }     return null; }  private static string convertstreamtostring(inputstream is) {      bufferedreader reader = new bufferedreader(new inputstreamreader(is));     stringbuilder sb = new stringbuilder();      string line = null;     try {         while ((line = reader.readline()) != null) {             sb.append(line + "\n");         }     } catch (ioexception e) {         e.printstacktrace();     } {         try {             is.close();         } catch (ioexception e) {             e.printstacktrace();         }     }     return sb.tostring(); }  } 

my log cat errors. starts bunch of xml activity pulling in information ends error

05-10 07:09:41.587: v/artistssearchactivity(796):           <identifier mbid="eb558587-e7a1-4f2b-9fda-b6ff5e137ed1" href="http://api.songkick.com/api/3.0/artists/mbid:eb558587-e7a1-4f2b-9fda-b6ff5e137ed1.xml"/> 05-10 07:09:41.587: v/artistssearchactivity(796):         </artist> 05-10 07:09:41.587: v/artistssearchactivity(796):       </performance> 05-10 07:09:41.587: v/artistssearchactivity(796):       <performance billingindex="3" displayname="love , death" billing="support" id="32720419"> 05-10 07:09:41.587: v/artistssearchactivity(796):         <artist displayname="love , death" uri="http://www.songkick.com/artists/286472-love-and-death?utm_source=19089&amp;utm_medium=partner" id="286472"> 05-10 07:09:41.587: v/artistssearchactivity(796):           <identifier mbid="27796970-8f7a-4196-9f7d-87f091af4412" href="http://api.songkick.com/api/3.0/artists/mbid:27796970-8f7a-4196-9f7d-87f091af4412.xml"/> 05-10 07:09:41.587: v/artistssearchactivity(796):           <identifier mbid="c29b667e-9895-41d2-b5a5-1817050ce0bc" href="http://api.songkick.com/api/3.0/artists/mbid:c29b667e-9895-41d2-b5a5-1817050ce0bc.xml"/> 05-10 07:09:41.587: v/artistssearchactivity(796):         </artist> 05-10 07:09:41.587: v/artistssearchactivity(796):       </performance> 05-10 07:09:41.587: v/artistssearchactivity(796):       <venue displayname="rostraver ice garden arena" lat="40.1981235" lng="-79.8294916" uri="http://www.songkick.com/venues/51599-rostraver-ice-garden-arena?utm_source=19089&amp;utm_medium=partner" id="51599"> 05-10 07:09:41.587: v/artistssearchactivity(796):         <metroarea displayname="belle vernon" uri="http://www.songkick.com/metro_areas/56020-us-belle-vernon?utm_source=19089&amp;utm_medium=partner" id="56020"> 05-10 07:09:41.587: v/artistssearchactivity(796):           <state displayname="pa"/> 05-10 07:09:41.587: v/artistssearchactivity(796):           <country displayname="us"/> 05-10 07:09:41.587: v/artistssearchactivity(796):         </metroarea> 05-10 07:09:41.587: v/artistssearchactivity(796):       </venue> 05-10 07:09:41.587: v/artistssearchactivity(796):       <start time="19:30:00" datetime="2013-05-15t19:30:00-0500" date="2013-05-15"/> 05-10 07:09:41.587: v/artistssearchactivity(796):       <location lat="40.1981235" lng="-79.8294916" city="belle vernon, pa, us"/> 05-10 07:09:41.587: v/artistssearchactivity(796):     </event> 05-10 07:09:41.587: v/artistssearchactivity(796):     <event type="festival" status="ok" displayname="rock on range 2013" uri="http://www.songkick.com/festivals/8261/id/14745014-rock-on-the-range-2013?utm_source=19089&amp;utm_medium=partner" popularity="0 05-10 07:09:41.637: i/choreographer(796): skipped 49 frames!  application may doing work on main thread. 05-10 07:09:43.807: e/trace(871): error opening trace file: no such file or directory (2) 05-10 07:09:45.357: e/trace(910): error opening trace file: no such file or directory (2) 05-10 07:09:45.687: e/trace(923): error opening trace file: no such file or directory (2) 05-10 07:09:46.307: e/trace(936): error opening trace file: no such file or directory (2) 05-10 07:09:47.167: e/trace(949): error opening trace file: no such file or directory (2) 05-10 07:09:48.337: e/trace(975): error opening trace file: no such file or directory (2) 

i have update. above code works! leave need it. problem having if xml string long search times out. how give android more time search?

  private void additemstolist(list<hashmap<string, string>> menuitems) {        listadapter adapter = new simpleadapter(this, menuitems,             r.layout.list_item_artist_calendar, new string[] { key_venue_name }, new  int[] { r.id.calendardisplayname });         setlistadapter(adapter);        adapter.notifydatasetchanged();     } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -