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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:06:22+00:00 2026-06-02T19:06:22+00:00

I have a button’s onClickListener that needs to detect which radiobutton was selected when

  • 0

I have a button’s onClickListener that needs to detect which radiobutton was selected when the user clicks the button. Currently, the Log.v you see below in the onClickListener is not returning a useless bit of info:

This is clicking submit three times with a different radio selected each time:

04-27 19:24:42.417: V/submit(1564): 1094168584

04-27 19:24:45.048: V/submit(1564): 1094167752

04-27 19:24:47.348: V/submit(1564): 1094211304

So, I need to know which radioButton is actually selected – is there a way to get the object of the radiobutton? I want to be able to get it’s id# from XML, as well as its current text.

Here’s the relevant code:

public void buildQuestions(JSONObject question) throws JSONException {

    radioGroup = (RadioGroup) questionBox.findViewById(R.id.responseRadioGroup);

    Button chartsButton = (Button) questionBox.findViewById(R.id.chartsButton);
    chartsButton.setTag(question);
    Button submitButton = (Button) questionBox.findViewById(R.id.submitButton);

    chartsButton.setOnClickListener(chartsListener);
    submitButton.setOnClickListener(submitListener);

    TagObj tagObj = new TagObj(question, radioGroup);
    submitButton.setTag(tagObj);

}

public OnClickListener submitListener = new OnClickListener() {
    public void onClick(View v) {
        userFunctions = new UserFunctions();
        if (userFunctions.isUserLoggedIn(activity)) {
            TagObj tagObject = (TagObj) v.getTag();
            RadioGroup radioGroup = tagObject.getRadioGroup();
            JSONObject question = tagObject.getQuestion();

            Log.v("submit", Integer.toString(radioGroup.getCheckedRadioButtonId()));
            SubmitTask submitTask = new SubmitTask((Polling) activity, question);
            submitTask.execute();

        }
    }   
};
  • 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-02T19:06:23+00:00Added an answer on June 2, 2026 at 7:06 pm

    getCheckedRadioButtonId() returns the id of the RadioButton(or -1 if no RadioButtons are checked) that is checked in the Radiogroup. If you set distinct ids to the RadioButons in the layout then you will try to match those ids with the return of the method to see which one is checked:

    //field in the class
    private static final int RB1_ID = 1000;//first radio button id
    private static final int RB2_ID = 1001;//second radio button id
    private static final int RB3_ID = 1002;//third radio button id
    
    //create the RadioButton
    RadioButton rb1 = new RadioButton(this);
    //set an id
    rb1.setId(RB1_ID);
    
    
        int btn = radioGroup.getCheckedRadioButtonId();
        switch (btn) {
        case RB1_ID:
            // the first RadioButton is checked.
        break;
            //other checks for the other RadioButtons ids from the RadioGroup
        case -1:
            // no RadioButton is checked inthe Radiogroup
        break;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have button, which fires an event, that deletes a record from the database.
I currently have Button in my main view which checks if users answer is
I have Button.When the user click the button, there are some condition, that condition
I have a button on my app that when I click (takes me to
I Have two button in opportunity page one is Save which is by default
I have a button on a page and I want that when it is
I have a button that I would like to disable when the form submits
I have a button on an ASP.Net page that will call Response.Redirect back to
I have button styles that look like this: .submit-button { display: block; color: red;
I have button on the page that being used as a link to another

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.