I want to change the values in an array in shared preferences. Can we make a string-array in shared preferences and use it in our code.? How is it possible as I am entering different values and want user to change values as per user need. I want to use those values in spinner.
Asked
Active
Viewed 946 times
0
-
2you can add multiple value in shared preference on the based of deliminator you can use any special char after insert a value. – Sandeep Nov 01 '12 at 05:13
3 Answers
1
Yes you can do that. Refer to Egor's comment in the link here Put and get String array from shared preferences
That is pretty much what you need.

Community
- 1
- 1

Abhishek Sabbarwal
- 3,758
- 1
- 26
- 41
0
you can not add array in sharedPrefence.. you can only use data type define in this doc. if you put a large number of data in sharedPrefence than that memory required never be free. so you can use Application class .. the memory of application class will be a free when app is force stop..

Sanket Kachhela
- 10,861
- 8
- 50
- 75
0
insert your values like
registrationPreferencesEditor.putInt("arraylength", a.length);
for(int i=0;i<a.length;i++)
{
registrationPreferencesEditor.putInt("a"+(i+1), a[i]);
}
registrationPreferencesEditor.commit();
retreive your values
int lengthOfArray = registrationPreferences.getInt("arraylength", 0);
int b[] = new int[lengthOfArray];
for(int i=0;i<lengthOfArray;i++)
{
b[i] = registrationPreferences.getInt("a"+(i+1), 0);
Log.e("b"+(i+1),""+b[i]);
}
before that make sure you have
SharedPreferences registrationPreferences;
SharedPreferences.Editor registrationPreferencesEditor;
int a[]={1,2,3,4,5};
registrationPreferences = getSharedPreferences("registrationPreferences",
MODE_WORLD_READABLE);
registrationPreferencesEditor= registrationPreferences
.edit();

Thirupathig
- 166
- 9