this is my array.xml file in 'res/values' folder

<resources>
    <string-array name="updateInterval">
           <item name="1000">Pico TTS</item>
          <item name="5000">Invox TTs</item>
    </string-array>
</resources>

I need to some more items to the 'updateInterval' array lsit. Please help me in this. how can I add the items that are dynamic coming from server programmatically.

Thanks in advance, Bharath Gangupalli

share|improve this question
2  
Sorry but you can't do this. You can load your array of strings at runtime and add to the array "in-memory" but you can't save them back to the strings.xml file. BTW, consider improving your accept rate - you've asked 23 questions, had answers to 17 of them but only accepted 2. – Squonk Jan 10 '12 at 6:54
...and one more thought. Consider maintaining a SQLite DB with new data coming from the server instead of a string array. – Squonk Jan 10 '12 at 6:56

2 Answers

You can't add item directly to that string array.

But you can use that array and dynamically add elements to that string array.

Do in this way.

    String[] array = getResources().getStringArray(R.array.updateInterval);
    System.out.println("--array.length--"+array.length);
    List<String> list = new ArrayList<String>();
    list = Arrays.asList(array);
    ArrayList<String> arrayList = new ArrayList<String>(list);
    arrayList.add("TTS");
    array = arrayList.toArray(new String[list.size()]);
    System.out.println("--array.length--"+array.length);
share|improve this answer
how does this add an item to "undateInterval" ? – GMT Dec 5 '12 at 6:46
He is showing you to create a new array based on the old one, then you can add things to it via the ArrayList and Array types. – Silas Greenback Jan 30 at 19:45

It is not possible to edit an xml resource dynamically, you just can have an static arraylist in case you need some data at runtime plus xml data.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.