Skip to content

Instantly share code, notes, and snippets.

@Antarix
Last active December 12, 2015 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Antarix/4705991 to your computer and use it in GitHub Desktop.
Save Antarix/4705991 to your computer and use it in GitHub Desktop.
fetches data from local Android xml folder having xml file and returns in Arraylist
public ArrayList<string> prepareListFromXml() {
ArrayList<string> todoItems = new ArrayList<string>();
XmlResourceParser todolistXml = getResources().getXml(R.xml.todolist);
int eventType = -1;
while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
String strNode = todolistXml.getName();
if (strNode.equals("item")) {
todoItems.add(todolistXml.getAttributeValue(null, "title"));
}
}
try {
eventType = todolistXml.next();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return todoItems;
}
<!--?xml version="1.0" encoding="utf-8"?-->
<todoitems>
<item title="Going to Gym" description="">
<item title="Get ready for office" description="">
<item title="Lunch with friends" description="">
<item title="Going to movie" description="">
</item></item></item></item></todoitems>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment