Defining hierarchy using XML in Android
I want to define a hierarchy as such:
Category 1
SubCategory 1.1
SubCategory 1.2
Category 2
SubCategory 2.1
And I would like to do it using Android's XML files (the ones that go inside the "values" folder) and not using code.
In a "regular" XML file I would do something like:
<category>
<id>1</id>
<title>Category 1</title>
</category>
<category>
<id>11</id>
<title>Category 1.1</title>
<parent_id>1</pa开发者_C百科rent_id>
</category>
Any suggestions? Thanks.
You should try putting your file in a res/xml/ folder instead of res/values/ and then you can access it like normal XML at runtime with Resources.getXML().
source: http://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes
精彩评论