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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:24:02+00:00 2026-06-14T22:24:02+00:00

I am still having problem with this radio buttons :(. I am still trying

  • 0

I am still having problem with this radio buttons :(. I am still trying to create a setting page which allow user to select their text colour and once they have selected from this setting activity and all other activities with listen to the sharedpreferences change as well.

I know how to save text and get text from a shared preferences between activities but int ? As I need the radio checked value and this method will be passed on to other activities to set those textview colours.

can anyone check the code for me please?

and I am very new to android and general programming.

public class Text_Colour extends Activity implements OnSharedPreferenceChangeListener {

    RadioButton rb1, rb2, rb3, rb4, rb5;
    TextView tv1, tv2;
    RadioGroup rg1;
    Button bt1;
    String red, yellow, green, blue;

    public static final String PREFS_NAME = "MyPrefsFile"; 


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

        loadPreferences();

        tv1 = (TextView)findViewById(R.id.textview1);
        tv2 = (TextView)findViewById(R.id.textview2);
        bt1 = (Button) findViewById(R.id.button1);
        rb1 = (RadioButton) findViewById(R.id.radioButton1);
        rb2 = (RadioButton) findViewById(R.id.radioButton2);
        rb3 = (RadioButton) findViewById(R.id.radioButton3);
        rb4 = (RadioButton) findViewById(R.id.radioButton4);
        rb5 = (RadioButton) findViewById(R.id.radioButton5);
        rg1 = (RadioGroup) findViewById(R.id.radiogroup1);

        bt1.setOnClickListener(Colour_change_b);

        //tv1.setOnSharedPreferenceChangeListener(this);

    }

    View.OnClickListener Colour_change_b = new View.OnClickListener() {

    public void onClick(View v) {

        if(v == bt1) {

             if (rb1.isChecked()== true) {
                 tv2.setTextColor(Color.RED);

                } 
                if (rb2.isChecked() == true) {
                    tv2.setTextColor(Color.YELLOW);

                } 
                if (rb3.isChecked() == true) {
                    tv2.setTextColor(Color.GREEN);

                } 
                if (rb4.isChecked() == true) {
                    tv2.setTextColor(Color.BLUE);

                } 
                if (rb5.isChecked() == true) {
                    rb5.getId();
                    tv2.setTextColor(Color.BLACK);

                } 
                else { 
                }
                SharedPreferences settings1 = getSharedPreferences(PREFS_NAME, 0);
                SharedPreferences.Editor editor = settings1.edit();
                editor.putInt("colour", rb1.getId());
                editor.commit();
                finish();   
    }
    }
    };
    private void loadPreferences() {
        // TODO Auto-generated method stub
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        tv1.setTextColor(settings.getId("colour", ""));
        settings.registerOnSharedPreferenceChangeListener(Text_Colour.this);
    }

    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
            String key) {

        loadPreferences();
    }   
    }

Much appreciated for your time guys.

  • 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-14T22:24:03+00:00Added an answer on June 14, 2026 at 10:24 pm

    Use your RadioGroup. You can use setOnCheckedChangeListener(RadioGroup.OnCheckedChangeListener listener) to receive instantly the value of the new color, and you can use getCheckedRadioButtonId() to get the checked radioButtonId.

    However, there is a catch. The Id is generated at compile time by android. It is not guaranteed to remain consistent between compilations. Use indexOfChild(View child) if you want to get the index of the RadioButton in the RadioGroup.

    To get the value, you need a getInt(), then a getChildAt(int index), then a getId() and a check(int id).

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

Sidebar

Related Questions

Still having issues with this problem. Please help if you can. So I am
I have asked this before however I am still having issues with this problem!
I'm having a problem with an ASP.NET MVC application that I'm developing. I'm still
I am having this problem in below code as my ArrayList both name and
I'm having this strange problem with cloned elements(using .clone(true)) with draggable and resizable functionalities
I'm trying to figure out this problem for one of my comp sci classes,
I was having this problem in IE7 where the saturdays appear to be missing
I have done quite a bit of research on this but I'm still having
I am having problem with this small piece of code SimpleDateFormat sf = new
Hi having a problem with this code even if i clicked on cancel it

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.