1

I have a res/values String-array that I would like users to be able to add new elements to via a form. I saw a post from 2011 that asked this question (How to update arrays in res/values/array.xml by code?) however, the answer stated that resource arrays are read-only at run time. I was wondering if anything has changed since 2011 that would allow users the ability to update the resource array (add new strings to it).

Community
  • 1
  • 1
Michael Carolan
  • 195
  • 2
  • 7

1 Answers1

2

Unfortunately resource values are still immutable. They are generated when your project is compiled and overriden on every compilation. There is a corresponding warning here in the documentation: https://developer.android.com/guide/topics/resources/accessing-resources.html

  • Thank you Dr. Nedolya - any ideas for a work around? I know you could do it with a db connection - but I kind of wanted to keep it stand-alone – Michael Carolan Jul 12 '16 at 01:17
  • @MichaelCarolan You can also try to store your array in SharedPreferences, like in this question: http://stackoverflow.com/questions/7361627/how-can-write-code-to-make-sharedpreferences-for-array-in-android/7361989#7361989 Another option is to store your data in standalone file which would be placed in your app's private directory. – Dmytro Nedolia Jul 12 '16 at 11:27