0

Here is my problem. I have a spinner on Main Activity class. In a separate class that I am using as preference class I have a list view with the same values of the spinner. I want the user to be able to select a value from the preference class list view and have that value automatically be set as the current value of the spinner in the main class. In addition, I want the value to be saved so that when the user starts up the app, the value that they selected to be the default value in the preference class is the one that is set on the spinner. I hope I have made myself clear enough. I did not supply any cod but I am working on a testing mock up of what I am trying to do that I will post a little later.

jdubicki
  • 289
  • 1
  • 6
  • 21

1 Answers1

0

Try this,

To store values in shared preferences:

  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
  SharedPreferences.Editor editor = preferences.edit();
  editor.putString("SpinnerValueKey","YourValue");
  editor.commit();

To retrieve values from shared preferences:

  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
  String YourValue = preferences.getString("SpinnerValueKey","");

If you want to get the Spinner Position by its name then you have see mypost here.

If You want more then you can find Here.

The android sdk's sample directory contains an example of retrieving and stroing shared preferences. Its located in the:

<android-sdk-home>/samples/android-<platformversion>/ApiDemos directory

If you app has complex storage then i recommend to go for Sqlite Database.

Hope it helps.

Community
  • 1
  • 1
vinothp
  • 9,939
  • 19
  • 61
  • 103