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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:30:22+00:00 2026-06-04T14:30:22+00:00

I am adding RadioButtons in my view by using a for loop, now I

  • 0

I am adding RadioButtons in my view by using a for loop, now I want to set a unique ID for each RadioButton.

for (int item = 0; item < 5; item++) {
    child = new RadioButton(this);
    itemRadioGroup.addView(child);
    child.setId(item);
}

Toast.makeText(getApplicationContext(), 
        String.valueOf(child.getID()), Toast.LENGTH_SHORT).show();

I want to set the ID of first button as 1, second button as 2, third as 3 and so on. But when I try to display the ID with a Toast message it shows me some garbage value rather than my set ID. How can I set ID properly?

  • 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-04T14:30:23+00:00Added an answer on June 4, 2026 at 2:30 pm

    I think it is because 0 is not a integer and your a giving an id of button as 0. where as the ids can only be positive integers..

      RadioButton child[]=new RadioButton[5];
      for (int item = 1; item <= 5; item++) {
     child[i]= new RadioButton(this);
     itemRadioGroup.addView(child[i]);
     child[i].setId(item);
     Toast.makeText(getApplicationContext(),child.getID()+ " ", Toast.LENGTH_SHORT).show();
     }
    //gets the checked radiobuttons ids
    
    for (int item = 1; item <= 5; item++) {
    if(child[i].isChecked()){
    
     Toast.makeText(getApplicationContext(),child[i].getID()+ " ", Toast.LENGTH_SHORT).show();
    
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to extend the RadioButton component in Flex 3, adding a text input
Adding contents to listview is a simple proceess like ListViewItem item = new ListViewItem();
I'm using this code to dynamically create new RadioButton in Android: RadioButton radioButton =
i am adding collection of radio buttons to my page using jQuery below $(document).ready(function()
Adding more than one child to a WPF StatusBar results in poor layout with
Adding some gui modifications and I want to have a button which is 10pixels
Adding the items in a checkedListBox : DirectoryInfo dinfo = new DirectoryInfo(@D:\\templates); FileInfo[] Files
Adding files to a specific directory using rackspace cloud files, c# bindings api more
I want to create a custom drawable for RadioButton's button drawable. I have created
I'm trying to add a couple of radiobuttons at the top of a View

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.