I'm developing an Android app. I'm using Jsoup to retreive elements from a page. Then, I'm iterating over the collection to get each individual part of it. I'm not sure how to save each instance of an element as a different variable. I think that I can use a for loop for this, but I don't quite understand it. How would I determine the length of how long to select from? How would I use it? I'm retreiving elements from here: http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=201412abc85d49b2b83f907f9e329eaa&mapid=40380. My code is 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 my = 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, like 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 would like to store each instance (there is many) of arrT, pdrt, and destNm as a different variable. How would I go across doing this? Thank you for your help.