java - Android -How can I open different list for single list row -
i have xml (i don't know if it's perfect):
<?xml version="1.0" encoding="utf-8"?> <lista> <riga> <id>1</id> <title>fornace</title> <thumb_url>http://i43.tinypic.com/29lzjpv.jpg</thumb_url> <prova> <title>prova1 - fornace</title> </prova> </riga> <riga> <id>2</id> <title>basilica</title> <thumb_url>http://i40.tinypic.com/qs8ihe.jpg</thumb_url> <prova> <title>prova2</title> </prova> </riga> <riga> <id>3</id> <title>foro boario</title> <prova> <title>prova3</title> </prova> </riga> </lista>
and want parse , open different lists single list row. how can do?
mainactivity:
public class lista extends activity { // static variables static string convertstreamtostring(java.io.inputstream is) { @suppresswarnings("resource") java.util.scanner s = new java.util.scanner(is).usedelimiter("\\a"); return s.hasnext() ? s.next() : ""; }; // static final string url = "lista_principale.xml"; // xml node keys static final string key_riga = "riga"; // parent node static final string key_id = "id"; static final string key_title = "title"; static final string key_thumb_url = "thumb_url"; static final string key_prova = "prova"; listview list; lazyadapter adapter; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_lista);
arraylist> listaelem = new arraylist>();
xmlparser parser = new xmlparser(); //string xml = parser.getxmlfromurl(url); // getting xml url inputstream = getresources().openrawresource(r.raw.lista_principale); string xml=convertstreamtostring(is); document doc = parser.getdomelement(xml); // getting dom element nodelist nl = doc.getelementsbytagname(key_riga); // 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_thumb_url, parser.getvalue(e, key_thumb_url)); map.put(key_prova, parser.getvalue(e, key_prova)); // adding hashlist arraylist listaelem.add(map); } list=(listview)findviewbyid(r.id.list); // getting adapter passing xml data arraylist adapter=new lazyadapter(this, listaelem); list.setadapter(adapter); // click event single list row list.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent = new intent(getapplicationcontext(), lista2.class); string posto_id = ((textview) view.findviewbyid(r.id.title)).gettext().tostring(); toast.maketext(getapplicationcontext(), "album id: " + posto_id , toast.length_short).show(); i.putextra("posto_id", posto_id); startactivity(i); } }); } }
singlelistactivity
public class lista2 extends activity { string posto_id = null; lazyadapter adapter; static string convertstreamtostring(java.io.inputstream is) { @suppresswarnings("resource") java.util.scanner s = new java.util.scanner(is).usedelimiter("\\a"); return s.hasnext() ? s.next() : ""; }; static final string key_title = "title"; static final string key_prova = "prova"; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_lista2); arraylist<hashmap<string, string>> listaelem = new arraylist<hashmap<string, string>>(); xmlparser parser = new xmlparser(); //string xml = parser.getxmlfromurl(url); // getting xml url inputstream = getresources().openrawresource(r.raw.lista_principale); string xml=convertstreamtostring(is); intent = getintent(); int k=0; k = i.getintextra("posto_id",k); // i.getstringextra(posto_id); document doc = parser.getdomelement(xml); nodelist nl = doc.getelementsbytagname(key_prova); (k=0; k< nl.getlength();k++){ hashmap<string, string> map2 = new hashmap<string, string>(); element f = (element) nl.item(k); map2.put(key_title, parser.getvalue(f, key_title)); listaelem.add(map2); } // displaying values on screen listview lblsong = (listview) findviewbyid(r.id.list2); adapter=new lazyadapter(this, listaelem); lblsong.setadapter(adapter); } }
Comments
Post a Comment