Last active
December 12, 2015 03:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--?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