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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:26:50+00:00 2026-05-31T03:26:50+00:00

my radio buttons work fine, except that the second one that is chosen becomes

  • 0

my radio buttons work fine, except that the second one that is chosen becomes sticky. others can be chosen and they toggle, but the display shows the second button stuck on.

please see self contained code example below. i am using 4.0.3 and running in the emulator using eclipse.

thanks

package small.example;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
public class SmallActivity extends Activity {
    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout main=new LinearLayout(this);
        main.setOrientation(LinearLayout.VERTICAL);
        int question=1;
        button=new Button(this);
        button.setText("Make a choice");
        main.addView(button);
        button.setId(question);
        setContentView(main);
        int answers=4;
        radioButtons=new RadioButton[answers];
        RadioGroup radioGroup=addRadioButtonsToGroup(question,radioButtons);
        LinearLayout linearLayout=new LinearLayout(this);
        linearLayout.addView(radioGroup);
        linearLayout.setId(question);
        // radioButtons[0].setChecked(true);
        main.addView(linearLayout);
    }
    private RadioGroup addRadioButtonsToGroup(int question,RadioButton[] radioButtons) {
        RadioGroup radioGroup=new RadioGroup(this);
        for(int i=0;i<radioButtons.length;i++) {
            radioButtons[i]=new RadioButton(this);
            radioButtons[i].setText("Question "+question+" Choice "+(i+1));
            radioButtons[i].setId(i);
            radioGroup.addView(radioButtons[i]);
        }
        radioGroup.setOnCheckedChangeListener(radioGroupOnCheckedChangeListener);
        radioGroup.setId(question);
        return radioGroup;
    }
    RadioButton[] radioButtons;
    Button button;
    RadioGroup.OnCheckedChangeListener radioGroupOnCheckedChangeListener=new RadioGroup.OnCheckedChangeListener(){
        public void onCheckedChanged(RadioGroup group,int checkedId) {
            int id=checkedId;
            button.setText(radioButtons[id].getText());
        }
    };
}
  • 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-31T03:26:52+00:00Added an answer on May 31, 2026 at 3:26 am

    It seems to be that the offending button shares an id with the radioGroup’s id, caused by the line

    radioGroup.setId(question);
    

    Why this should cause the button to be sticky isn’t clear to me. If you change that line to

    radioGroup.setId(radioGroup.getChildCount());
    

    thereby giving it a non-clashing id, all buttons work OK.

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

Sidebar

Related Questions

i have 3 radio buttons.what i need to do is that when one radio
The radio buttons when selected work fine in terms of outputting a selected color
I have a website at tbmaster.co.uk which has 3 radio buttons and they work
I am guessing getElementById doesn't work with radio buttons when you want to get
How can i add radio buttons in android app with option as an image
I have two radio buttons on my MVC form that I use to hide
I have two radio buttons next to each other, and even though each one
Why my labels and radio buttons won't stay in the same line, what can
Probably a simple one, but I need some help. I had some radio buttons
I have a table of radio buttons that have an ID value that contains

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.