Suppose Type is the name of the array which contains A,B,C,D as elements and is created in strings.xml.Now in the form user can either select any of the elements or add new elements.Suppose user adds E,F,G .Now what i want to achieve is that anyhow the Type array have A,B,C,D,E,F,G in it. Using sqlite is done.But i want to save it in the Type array only and not anywhere else.Is it possible ?
Asked
Active
Viewed 71 times
2 Answers
0
Since anything that you define in res folder acquires a unique id in R.java, which is an array, and size of array cannot be changed at runtime.. So, it is not possible.

Abhishek Shukla
- 1,242
- 8
- 11
-
Create what? If you are talking about creating the R.java, android creates this itself according to the elements you defined in your res folder. – Abhishek Shukla Jul 19 '13 at 09:10
-
I meant create the array through code and then try and achieve the same thing – sankettt Jul 19 '13 at 09:14
-
Also, you don't have write access in res folder.. you only have read access through codes.. because anything that you put in res folder increases the apk size.. – Abhishek Shukla Jul 19 '13 at 09:18
-
Yes if i do through code is it possible i mean create the array in the java file and not in the xml and if yes then how to go about it ? – sankettt Jul 19 '13 at 09:22
0
You can only save data to persistent storage like SQLite data base, shared preferences or a text file, each of which have different strengths and weaknesses and are suited for different situations, so take your pick.

Goran Horia Mihail
- 3,536
- 2
- 29
- 40
-
-
it can be done although a bit tricky, see this: http://stackoverflow.com/questions/7057845/save-arraylist-to-sharedpreferences – Goran Horia Mihail Jul 19 '13 at 10:41
-
seen this one as well it says api level 11 and above and my app is supported from version 4 though it actually should be from 8 – sankettt Jul 19 '13 at 10:47
-
Found one way though saving it as string and the creating the array by using split() function – sankettt Jul 19 '13 at 10:48
-
1Here's one method to save an array of strings to shared preferences regardless of api level: http://stackoverflow.com/questions/7965290/put-and-get-string-array-from-shared-preferences – Goran Horia Mihail Jul 19 '13 at 13:18
-
yup thats what i thought.But still i have this question if its possible to create an array in a java file and append an element as my question goes and save that change and once again when i access the java file i get those values without using a text file.May be by creating a class or anything like that. – sankettt Jul 19 '13 at 13:23