Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:34:12+00:00 2026-05-26T19:34:12+00:00

OK here is my problem. I have a spinner and every option in spinner

  • 0

OK here is my problem. I have a spinner and every option in spinner should edit textview in my layout (option in spinner you can see in position command), so I have made it with SharedPreferences, it is not problem, when I select some option in spinner, so the textview is changed, but when I kill my app and then re-open, the textview is default (the same as defined in my layout). So where is the problem?

First Activity:

if(position == 4){
    SharedPreferences myPrefsUv = CPUActivity.this.getSharedPreferences("myPrefsUv", MODE_PRIVATE);
    SharedPreferences.Editor prefsEditorUv = myPrefsUv.edit();
    prefsEditorUv.putString(maxUv, "1");
    prefsEditorUv.commit();
}

if(position == 5){
    SharedPreferences myPrefsUv = CPUActivity.this.getSharedPreferences("myPrefsUv", MODE_PRIVATE);
    SharedPreferences.Editor prefsEditorUv = myPrefsUv.edit();
    prefsEditorUv.putString(maxUv, "2");
    prefsEditorUv.commit();
}

if(position == 6){
    SharedPreferences myPrefsUv = CPUActivity.this.getSharedPreferences("myPrefsUv", MODE_PRIVATE);
    SharedPreferences.Editor prefsEditorUv = myPrefsUv.edit();
    prefsEditorUv.putString(maxUv, "3");
    prefsEditorUv.commit();
}

if(position == 7){
    SharedPreferences myPrefsUv = CPUActivity.this.getSharedPreferences("myPrefsUv", MODE_PRIVATE);
    SharedPreferences.Editor prefsEditorUv = myPrefsUv.edit();
    prefsEditorUv.putString(maxUv, "4");
    prefsEditorUv.commit();
}

Second Activity:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_layout);

        SharedPreferences myPrefsUv = UVActivity.this.getSharedPreferences("myPrefsUv", MODE_PRIVATE);
        String prefNameUv = myPrefsUv.getString(maxUv, "");
        if(prefNameUv == "1"){
            final TextView textUv = (TextView)findViewById(R.id.text_max);
            textUv.setText("100");
        }
        if(prefNameUv == "2"){
            final TextView textUv = (TextView)findViewById(R.id.text_max);
            textUv.setText("110");
        }
        if(prefNameUv == "3"){
            final TextView textUv = (TextView)findViewById(R.id.text_max);
            textUv.setText("120");
        }
        if(prefNameUv == "4"){
            final TextView textUv = (TextView)findViewById(R.id.text_max);
            textUv.setText("130");
        }
    }

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:34:12+00:00Added an answer on May 26, 2026 at 7:34 pm

    You are adding the different values with the same key? This way I think it will always return the first match. I don’t see in your code “maxUv” to be assigned different values, according to the different cases.

    1) I suggest you move to if/else construct. This way, when you’re in the right case, the remaining conditions are not evaluated.

    2) call the following lines outside the if/else construct. You don’t need to get the SharedPreferences Editor in every case.

    SharedPreferences myPrefsUv = CPUActivity.this.getSharedPreferences("myPrefsUv", MODE_PRIVATE);
    SharedPreferences.Editor prefsEditorUv = myPrefsUv.edit();
    

    Same for the acquiring of TextView textUv in the second Activity. Just acquire reference once, and use the same reference in all cases.

    3) In the second Activity, you’re also comparing Strings with == operator, but Strings should be compared with equals().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my problem: I have an application that every iteration it returns to
Here's my problem: I have an array, which contains a command a[1], followed by
Here is the problem I have: I have a lot (tens of thousands) of
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
Here's my problem: I have a virtual method defined in a .h file that
Here is the problem: we have lots of Javascripts and lots of CSS files,
Here's my problem: I have to call a web service with a secure header
Here's my problem.I have 2 xmlfiles with identical structure, with the second xml containing
Here is the problem: We have all of our development under subversion, but our
Here's my problem: I have do create a menu/list of actions (which would be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.