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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:48:29+00:00 2026-06-10T21:48:29+00:00

I have two radio button groups in a view for a dialog box for

  • 0

I have two radio button groups in a view for a dialog box for my user to select the display color they want. I created two groups because of size constraints. Because the two groups do not remain mutually exclusive when separated I need to check for a change from group1 to group2 and clear the selection from the other group. I did this by adding an onCheckedChangeListener() to each group as follows:

    RadioGroup rGroup1 = (RadioGroup)currentDialog.findViewById(R.id.rgColors1);
     rGroup1.setOnCheckedChangeListener(new OnCheckedChangeListener(){
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if(checkedId != -1)
            {
                RadioGroup rGroup2 = (RadioGroup) currentDialog.findViewById(R.id.rgColors2);
                rGroup2.clearCheck();
            }
        }

      });

     RadioGroup rGroup2 = (RadioGroup) currentDialog.findViewById(R.id.rgColors2);
     rGroup2.setOnCheckedChangeListener(new OnCheckedChangeListener(){

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if(checkedId != -1)
            {
                RadioGroup rGroup1 = (RadioGroup) currentDialog.findViewById(R.id.rgColors1);
                rGroup1.clearCheck();
            }
        }

     });

And my Dialog layout looks like the following:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/colorDialogLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:minWidth="300dp"
android:orientation="vertical">
<TableLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tableLayout"
    android:padding="5dp">
    <TableRow android:gravity="center">
        <RadioGroup android:id="@+id/rgColors1">
            <RadioButton android:id="@+id/black_radio" 
                android:text="@string/option_black" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <RadioButton android:id="@+id/blue_radio" 
                android:text="@string/option_blue" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <RadioButton android:id="@+id/green_radio" 
                android:text="@string/option_green" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <RadioButton android:id="@+id/orange_radio" 
                android:text="@string/option_orange" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <RadioButton android:id="@+id/pink_radio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/option_pink" />
        </RadioGroup>
        <RadioGroup android:id="@+id/rgColors2">
            <RadioButton android:id="@+id/purple_radio" 
                android:text="@string/option_purple" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <RadioButton android:id="@+id/red_radio" 
                android:text="@string/option_red" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <RadioButton android:id="@+id/teal_radio" 
                android:text="@string/option_teal" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <RadioButton android:id="@+id/yellow_radio" 
                android:text="@string/option_yellow" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </RadioGroup>
    </TableRow>
</TableLayout>
<Button android:id="@+id/setBackColorButton"
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"  
  android:layout_gravity="center_horizontal"
  android:text="@string/button_set_back_color"/>

When a radiobutton is selected from either group then the group it is not part of is cleared. The issue I am having is that the radio button that was selected does not show as checked and must be selected a second time. My suspicion is that the clearCheck() is running for both radiogroups but I am not sure why or how to prevent this behavior. Any help would be much appreciated.

  • 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-10T21:48:30+00:00Added an answer on June 10, 2026 at 9:48 pm

    In the end I had to create an onclick() event for each radio button. The reason I think my first approach does not work is because the onselectchange() event is fired when setting the selection to none. In testing various methods of using this method of setting the second group to none resulted in needing to perform the selection a second time or an infinite loop of the two groups setting each other to none. I believe in the case of needing to perform the selection a second time is because the procedure does not return control to the calling procedure to finish the selection. I am a little green to Android so I could be completely off base. In the end however the separate onclick() event does work.

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

Sidebar

Related Questions

I have two radio button groups in my partial view and based on the
I have two forms, one with a radio button that users must select to
I have created a radio group which contains two buttons, I can select one
I have two radio button categories: color1 and color2. Color 1 can be either
I have 2 radio button groups. The two buttons are radioGroupLoanType and radioGroupLoanType. The
I have a radio group defined with two buttons for black and color. When
I have two fields which calculate a total, but I have a radio button
I have those two html radio buttons and textarea. I basically want to enable
I have to add one text view and two radio buttons in the scroll
I have an MFC dialog in which there are two radio buttons. I have

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.