java - How to store values as variables in iterator, for loop? -
i'm developing android app. i'm using jsoup retreive elements page. then, i'm iterating on collection each individual part of it. i'm not sure how save each instance of element different variable. think can use loop this, don't quite understand it. how determine length of how long select from? how use it? i'm retreiving elements here: http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=201412abc85d49b2b83f907f9e329eaa&mapid=40380. code below:
public class teststation extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.test_station); strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); intent intent = getintent(); string value = intent.getextras().getstring("value"); uri = uri.parse("http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=201412abc85d49b2b83f907f9e329eaa&mapid="+value); string myurl = my.tostring(); document doc = null; textview tv1 = (textview) findviewbyid(r.id.tv1); try { doc = jsoup.connect(myurl).useragent("mozilla/5.0 (macintosh; u; intel mac os x; de-de) applewebkit/523.10.3 (khtml, gecko) version/3.0.4 safari/523.10").get(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } elements elem = doc.select("eta"); iterator<element> iterator = elem.iterator(); while(iterator.hasnext()) { element div = iterator.next(); elements arrt = div.select("arrt"); elements prdt = div.select("prdt"); elements destnm = div.select("destnm"); elements rt = div.select("rt"); string destnm = destnm.text(); string rt = rt.text(); tv1.settext(string.valueof (rt));
i store each instance (there many) of arrt, pdrt, , destnm different variable. how go across doing this? thank help.
you use generic type list
arraylist<elements> xx = new arraylist<elements>();
then in while loop
xx.add(arrt);
Comments
Post a Comment