简体   繁体   中英

Android XML resource format/structure

How to properly write android xml resource where object has a main ID and sub-objects has subID's

I have very good example to explain my problem. Example is written in Plist(modified xml version for iOS):

<plist version="1.0">
<dict>
<key>223</key>----main key/ID
<dict>
<key>name</key>----sub-key/ID
  <string>Bill</string>
<key>uzvards</key>
  <string>Gates</string>
<key>adress</key>
  <string>Broadway</string>

So i need this type of data structure written in android XML. I guess xml file should be created in Values folder and use Resource type !? Thank you.

After looking into Plist, I think my comment was a suitable answer. In your actual code, you will want to use something like a hashmap , for your data. Depending on what you want, there are numerous ways to set this up but you can create a new hashmap

HashMap<String, String> myMap = new Hash<String, String>(); 

then use put(key, value) to add things to the map which you may get from a TextView and could display in an EditText. You can also use ArrayList and many others depending on what you want to accomplish. Or HashMaps inside of HashMaps. Note: if you want to keep the order of your map you will want to use a linked hashmap The res directory is where you store your XML for layouts(UI). My comment link should explain that very well. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM