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

  • Home
  • SEARCH
  • 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 7961871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:10:19+00:00 2026-06-04T05:10:19+00:00

I have created a radio group which contains two buttons, I can select one

  • 0

I have created a radio group which contains two buttons, I can select one and save it, it works fine, still stored after closing the app. What I want to do is use the value of the radio buttons in another class. Here is my settings class which contains the shared preferences code:

public class Settings extends Activity {
private String settingsTAG = "AppNameSettings";
private SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.settings);
    prefs = getSharedPreferences(settingsTAG, 0);

    final RadioButton rb0 = (RadioButton) findViewById(R.id.radioInternetYes);
    final RadioButton rb1 = (RadioButton) findViewById(R.id.radioInternetNo);

    rb0.setChecked(prefs.getBoolean("rb0", true));
    rb1.setChecked(prefs.getBoolean("rb1", false));     
    Button btnSave = (Button) findViewById(R.id.btnSave);

    btnSave.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            prefs = getSharedPreferences(settingsTAG, 0);
            Editor editor = prefs.edit();

            editor.putBoolean("rb0", rb0.isChecked());
            editor.putBoolean("rb1", rb1.isChecked());
            editor.commit();

            finish();

        }
    } );

}

In another class I am trying to check if rb0 is true or false when clicking a button:

share.setOnClickListener(new View.OnClickListener(){

        public void onClick(View v) {
            if(rb0 = true){
            Intent i = new Intent(Intent.ACTION_SEND);

            i.setType("text/plain");

            i.putExtra(Intent.EXTRA_EMAIL  , new String[]{""});

            i.putExtra(Intent.EXTRA_SUBJECT, "Check out my awesome score!");
            i.putExtra(Intent.EXTRA_TEXT   , "I am playing this awesome game called Tap the Button, and I just scored the incredible highscore of " +s+ " Taps!!\n\nCan you beat it!?");
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(FailScreen.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }
        }
            else{
                //Display warning that rb0 is false
            }
                }
    });

I have researched Stackoverflow and the developer documentation, but I cant seem to find out how this can be done, any advice is appreciated.

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-06-04T05:10:21+00:00Added an answer on June 4, 2026 at 5:10 am

    Instead of if(rb0 = true) (which should be == anyways), you need to access the SharedPreferences again. Quoted from http://developer.android.com/guide/topics/data/data-storage.html:

    To read values, use SharedPreferences methods such as getBoolean() and
    getString().

    So you would use something like:

    String settingsTAG = "AppNameSettings";
    SharedPreferences prefs = getSharedPreferences(settingsTAG, 0);
    boolean rb0 = prefs.getBoolean("rb0", false);
    if(rb0 == true){ 
        // Do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table which contains a bunch of dynamically created radio button lists,
I have created a simple wp7 application which contains 2 pages both with a
I have six radio buttons in XAML, and I would like to create two
I use an object to check that a group of radio buttons have a
I need to select a radio button dynamically. i) I have created few radio
I have Radio buttons that are created dynamically. LinearLayout linLayRoot = (LinearLayout)dialogView.findViewById(R.id.dialog_layout_root); RadioGroup radGp
Situation:- I have created a RadioButton group. When a User selects a radio button
I have a form that is dynamically created, on this form are several radio
I have created a file with XmlDocument xmldoc = new XmlDocument(); Can I make
i have created a simple public ref class in the vc++ project, which is

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.