Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 =;
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
return todoItems;
<!--?xml version="1.0" encoding="utf-8"?-->
<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="">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment