Changes

Jump to: navigation, search

Android Discovery Zone

1,571 bytes added, 21:21, 28 November 2013
no edit summary
right click on it, select run as android application. As long as your device runs the minimum SDK version listed in your apps manifest file (ie: <uses-sdk android:minSdkVersion="10" />) then your device should be on the list of devices where you can run and debug your app. Most devices can run a SDKVersion 8 though for some of the later labs you might need SDKVersion 10.
 
=Parsing XML Attributes=
 
This section shows how to parse xml attributes using xmlpullparser like in the example below
 
<stop tag="473" title="Humber Loop At The Queensway" lat="43.6310799" lon="-79.47871" stopId="13692"/>
 
The first step will be to create a class that contains the attributes you wish to retrieve more than one attribute from the xml tag.
 
the next step will be to create an arraylist of either that class you just created or an arraylist of Strings (or any other type but Strings is recommended).
 
ie: ArrayList<Stop> stopArray = new ArrayList<Stop>();
 
do the xml pull parsing like here
 
http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
 
at the start tag section check for the tag whose attributes you wish to retrieve by calling xmlpullparser's getName method to get the current xml tag it is on and using string compare with a string containing the tag you wish to compare it to and use the getAttributeValue method as seen below to retrive the value of xml tag's attribute you wish to retrieve.
 
 
 
else if(eventType == XmlPullParser.START_TAG) {
if("stop".equals(parser.getName())){
if(parser.getAttributeValue(null, "stopId") != null){
String myTag = parser.getAttributeValue(null, "tag");
 
after this is done, add your String (or object) into your array. Be sure to do this while inside the the while(eventType != XmlPullParser.END_DOCUMENT) loop
 
stopArray.add(myTag);}
 
Once all this is done you can now work with the values of the xml attributes by just going through the arraylist.
1
edit

Navigation menu