简体   繁体   中英

How to Add items to the string.xml using edittext?

<string name="AAAAA">Select a item"</string>

<string-array name="planets_array">
    <item>AAA</item>
    <item>BBB</item>
    <item>CCC</item>
    <item>DDD</item>
    <item>EEE</item>
    <item>FFF</item>

</string-array>

I want to add new item to the string.xml file using edittext.(user inputs). Could someone please tell me the way to insert a value to XML in this case? If you have any worked through examples, that would be a real help!

Why do you need to edit string.xml file from code? If you need to make a string array, create a Array list of string in java code, and add the values to it from string.xml.

Actually this is not possible. string.xml is compiled with all the other resource files to the .apk file. It can't be accessed at runtime. You can store your strings in SharedPreferences or create files on user's SD card.

my idea is that store the values in ArrayList it is better option and u can also display in List.

All The Best

From your comment:

I need to connect with one array using multiple spinners in different layouts.That's why i try to use the string.xml file.How can i do this..?

=> Define a static ArrayList in separate class, and then add/delete value from it whenever you required from any activity.

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