Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Mobile Development
  3. Android
  4. Android sharedPreferences not working on spinner

Android sharedPreferences not working on spinner

Scheduled Pinned Locked Moved Android
androidquestion
4 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pankaj788
    wrote on last edited by
    #1

    How save spinner data using sharedPreferences and How that data load in that spinner after reopening of the activity?

    D 1 Reply Last reply
    0
    • P pankaj788

      How save spinner data using sharedPreferences and How that data load in that spinner after reopening of the activity?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      pankaj788 wrote:

      How save spinner data using sharedPreferences...

      Assuming you already have the data from the spinner, try:

      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
      Editor editor = prefs.edit();
      editor.putString(key, value_obtained_from_spinner);
      editor.commit();

      pankaj788 wrote:

      ...How that data load in that spinner after reopening of the activity?

      In onCreate(), onStart(), or onResume(), you'll need something like:

      String value = prefs.getString(key);
      int pos = adapter_tied_to_spinner.getPosition(value);
      spinner.setSelection(pos);

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      P 1 Reply Last reply
      0
      • D David Crow

        pankaj788 wrote:

        How save spinner data using sharedPreferences...

        Assuming you already have the data from the spinner, try:

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        Editor editor = prefs.edit();
        editor.putString(key, value_obtained_from_spinner);
        editor.commit();

        pankaj788 wrote:

        ...How that data load in that spinner after reopening of the activity?

        In onCreate(), onStart(), or onResume(), you'll need something like:

        String value = prefs.getString(key);
        int pos = adapter_tied_to_spinner.getPosition(value);
        spinner.setSelection(pos);

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        P Offline
        P Offline
        pankaj788
        wrote on last edited by
        #3

        I have used the above code in my activity but nothing append anything. :( Can you give me the activity? Cause I am new in Android. And What is "key, value_obtained_from_spinner"? Cause I have created the the spinner programmatically.

        D 1 Reply Last reply
        0
        • P pankaj788

          I have used the above code in my activity but nothing append anything. :( Can you give me the activity? Cause I am new in Android. And What is "key, value_obtained_from_spinner"? Cause I have created the the spinner programmatically.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          pankaj788 wrote:

          Can you give me the activity?

          I don't have an activity. I just pulled that code off the top of my head.

          pankaj788 wrote:

          What is "key, value_obtained_from_spinner"?

          See [here](http://developer.android.com/reference/android/content/SharedPreferences.Editor.html#putString\(java.lang.String, java.lang.String)).

          pankaj788 wrote:

          Cause I have created the the spinner programmatically.

          Any reason why?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups