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 7654859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:21:52+00:00 2026-05-31T12:21:52+00:00

I have two different activities. One’s view contains RadioButton s that give the user

  • 0

I have two different activities. One’s view contains RadioButtons that give the user choice to select color, then when the user draws on the Canvas,the color selected in the options activity is used to draw.
Here’s the code for the Options Activity:

            RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
            int checkedRadioButton = radioGroup.getCheckedRadioButtonId();

            String radioButtonSelected = "";
            switch (checkedRadioButton) {
              case R.id.CheckRed : radioButtonSelected = "Red";
                                              break;
              case R.id.CheckBlue : radioButtonSelected = "Blue";
                                          break;
              case R.id.CheckWhite : radioButtonSelected = "White";
                                          break;
            }
            SharedPreferences appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
            Editor prefsEditor = appSharedPrefs.edit();
            prefsEditor.putString("setColor", radioButtonSelected);
            prefsEditor.commit();

Here’s the xml for this Activity:

    <RadioGroup 
        android:id="@+id/radiogroup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:orientation="vertical" >


    <RadioButton 
        android:id="@+id/CheckWhite"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="White" />

    <RadioButton 
        android:id="@+id/CheckRed" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="Red" />

    <RadioButton
        android:id="@+id/CheckBlue" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Blue" />

</RadioGroup>

Notice that CheckWhite has android:checked="true". I want that to be true for whichever color the user selects later on.

Here’s the code for the Activity that does the drawing:

        SharedPreferences appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
        drawColor = appSharedPrefs.getString("setColor", "White");
        if(drawColor.equals("White"))
            intColor = 1;
        if(drawColor.equals("Red"))
            intColor = 2;
        if(drawColor.equals("Blue"))
            intColor = 3;


        mPaint = new Paint();
        if(intColor == 1)
            mPaint.setColor(Color.WHITE);
        if(intColor == 2)
            mPaint.setColor(Color.RED);
        if(intColor == 3)
            mPaint.setColor(Color.BLUE);

Unfortunately,the color doesn’t change. Kindly help!

  • 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-31T12:21:54+00:00Added an answer on May 31, 2026 at 12:21 pm

    Add a OnCheckedChangedListener to your RadioGroup and in the method onCheckedChanged(RadioGroup group, int checkedId) put the code that sets the preferences for the user color. Some code:

    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    String radioButtonSelected = "";
                    switch (checkedId) {
                      case R.id.CheckRed : radioButtonSelected = "Red";
                                                      break;
                      case R.id.CheckBlue : radioButtonSelected = "Blue";
                                                  break;
                      case R.id.CheckWhite : radioButtonSelected = "White";
                                                  break;
                    }
                    SharedPreferences appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
                    Editor prefsEditor = appSharedPrefs.edit();
                    prefsEditor.putString("setColor", radioButtonSelected);
                    prefsEditor.commit();
    
                }
            });
    

    EDIT:
    Remove the android:checked="true" from the xml layout (from the white RadioButon) and then in your Options screen set the checked RadioButton according to your preferences:

    RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
    radioGroup.clearCheck();
    SharedPreferences appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
    drawColor = appSharedPrefs.getString("setColor", "White");
    if(drawColor.equals("White"))
        radioGroup.check(R.id.CheckWhite);
    if(drawColor.equals("Red"))
        radioGroup.check(R.id.CheckRed);
    if(drawColor.equals("Blue"))
        radioGroup.check(R.id.CheckBlue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different modules that need access to a single file (One will
I have two different activities. The first launches the second one. In the second
In one of my Activities I do have up to six different AsyncTasks that
I have two different projects and in one, I have a class that defines
I have two different Search activities implemented with SearchManager in my app. One is
I have two activities with same name on two different packages. One is just
I have here two applications in two different projects in eclipse. One application (A)
In my application, I have two different activities and both are list activities. I
I have one problem using ActivityGroup. I have two activities inside an ActivityGroup and
I have two different arrays. One array, a, for a list of people. My

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.