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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:55:32+00:00 2026-05-26T04:55:32+00:00

I am trying to use this Android: How to get a radiogroup with togglebuttons?

  • 0

I am trying to use this Android: How to get a radiogroup with togglebuttons? code of the given answer

but in

static final RadioGroup.OnCheckedChangeListener ToggleListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final RadioGroup radioGroup, final int i) {
            for (int j = 0; j < radioGroup.getChildCount(); j++) {
                final ToggleButton view = (ToggleButton) radioGroup.getChildAt(j);
                view.setChecked(view.getId() == i);
            }
        }
    };

in line

final ToggleButton view = (ToggleButton) radioGroup.getChildAt(j);

it always crashes. In Logcat I don’t see any message.

I tried everything I could think of , but can’t fid the problem –
Many thanks!

ps this is my xml for the radiogroup:

   <RadioGroup android:id="@+id/radioGroup2" android:layout_width="150sp" android:layout_height="wrap_content" 
            android:paddingLeft = "10sp" android:layout_alignBottom="@+id/a2"  >
        <RadioButton android:layout_width="wrap_content" android:id="@+id/Settings_otherSettingsT2Yes" android:layout_height="wrap_content" 
            android:textColor="#000000" android:textSize="18sp"
        android:text="@string/Settings_otherSettingsT2Yes" android:checked="false"></RadioButton>
        <RadioButton android:layout_width="wrap_content" android:id="@+id/Settings_otherSettingsT2No" android:layout_height="wrap_content" 
            android:textColor="#000000" android:textSize="18sp"
        android:text="@string/Settings_otherSettingsT2No"></RadioButton>
    </RadioGroup>

…nothing special here

I checked the number of children by logging radioGroup.getChildCount() and it gives 2 as expected

  • 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-26T04:55:33+00:00Added an answer on May 26, 2026 at 4:55 am

    In your code you cast RadioButtons to ToggleButton. This is likely to be the cause of your crashes. I don’t understand why you can’t find an exception in logcat.

    However, you say you want to use code like in the link, but your XML is not close to the link. You use RadioButtons where the link uses ToggleButtons.

    If you just want RadioButtons, then completely disregard that link.
    If you want to use ToggleButtons then that link isn’t the best way anyway. Adding ToggleButtons to a RadioGroup just confuses the intent of the code.

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

Sidebar

Related Questions

I'm trying to use this library http://code.google.com/p/svg-android/ to get SVGs into android. Here's my
I'm trying to get android unique id i'm using this code to get android
I am trying to use OnItemLongClickListener for a listView on Android. This code works
I'm trying to use this tutorial on Restlet for Android, and can't get the
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I'm trying to use this layout with two 50% column width instead. But it
i am trying to use this code to bind my asp.net menu control to
I'm trying to use this code to replace spaces with _, it works for
i am trying to use this code: <%= File.ReadAllText(Server.MapPath(Members/newsletters/welcome.html))%> which works great but now
i'm trying to use C2DM client with this tutorial:http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html I'm using this code for

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.