protected override void OnStart() { base.OnStart(); peopleList = (ListView)FindViewById(Resource.Id.peopleList); if (v == null) { GetUpis(); v = new VCard[upiList.Length]; for (int i = 0; i < upiList.Length; i++) { v [i] = new VCard("", upiList [i], "no homepage", "", "no picture"); } ThreadPool.QueueUserWorkItem(o => GetPeople()); } Thread.Sleep(2000); peopleList.Adapter = new PeopleListAdapter(this, upiList); }
public void GetPeople() //consumes url to produce an array of v-cards for each person { XmlDocument upisxml = new XmlDocument(); upisxml.Load("http://redsox.tcs.auckland.ac.nz/CSS/CSService.svc/people"); XmlNodeList uPIField = upisxml.GetElementsByTagName("uPIField"); MemoryStream vcardstream; for (int i = 0; i < uPIField.Count; i++) { vcardstream = new MemoryStream(new WebClient().DownloadData(" http://www.cs.auckland.ac.nz/our_staff/vcard.php?upi=" + uPIField [i].InnerText)); var sr = new StreamReader(vcardstream); var vcardstr = sr.ReadToEnd(); //get v-card as one string string[] vcardfields = vcardstr.Split(':'); //: is delimiter in v-card for (int j = 0; j < vcardfields.Length; j++) { string[] temp = vcardfields [j].Split((char)13); //carraige return is also a delimiter vcardfields [j] = temp [0]; } if (vcardfields [11] == "") //v card does not have a homepage { v [i] = new VCard(vcardfields [3], vcardfields [6], "no homepage", vcardfields [9], vcardfields [12]); } else { v [i] = new VCard(vcardfields [3], vcardfields [6], vcardfields [11] + ":" + vcardfields [12], vcardfields [9], vcardfields [13]); //index 11 + 12 due to : in http:// } //v [i].ToDebugString (); //debug, prints all v-cards } }