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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:46:51+00:00 2026-05-31T11:46:51+00:00

tI have 2 radio buttons, 1 is defaulted to start as true, when app

  • 0

tI have 2 radio buttons, 1 is defaulted to start as true, when app loads.
If 1 is selected it hides table 2. and if Radiobutton 2 is selected it hides table 1.
This works as intended except…
The problem I am having is, when the app first loads Radiobutton 1 is checked, but both tables are open, until i select radiobutton 2 then it starts working. So I am missing something in my initial load.

A nudge in the right direction would be greatly appreciated.

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TableLayout;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class Slab  extends Activity {
private RadioGroup RadioMeat;

/** Called when the activity is first created. */
//@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.slab);

    RadioMeat = (RadioGroup) findViewById(R.id.rgMeat);        
    RadioMeat.setOnCheckedChangeListener(new OnCheckedChangeListener() 
    {

        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.rbBeef :
                if (checkedId == R.id.rbBeef) {
                    TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
                    tl.setVisibility(View.VISIBLE);
                    TableLayout tl1 = (TableLayout)findViewById(R.id.tableLayout2);
                    tl1.setVisibility(View.GONE);
                } 
                break;
            case R.id.rbPork :
                 if (checkedId == R.id.rbPork) {
                    TableLayout tl = (TableLayout)findViewById(R.id.tableLayout2);
                    tl.setVisibility(View.VISIBLE);
                    TableLayout tl1 = (TableLayout)findViewById(R.id.tableLayout1);
                    tl1.setVisibility(View.GONE);
                }
                break;

        }
        }
    });
}

}

XML

<RadioGroup
        android:id="@+id/rgMeat"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RadioButton
            android:id="@+id/rbBeef"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Beef" 
            android:checked="true"/>

        <RadioButton
            android:id="@+id/rbPork"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Pork" />
    </RadioGroup>
  • 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-31T11:46:53+00:00Added an answer on May 31, 2026 at 11:46 am

    The problem you are facing is that at the time of start, when your onCreate() is called first, onCheckedChanged() is never called. It is called only when you check it. It would have also been called had you checked it programatically rather than do it through xml. So you could do it 2 ways,

    in your on create()

    Call

    ((TableLayout)findViewById(R.id.tableLayout2)).setVisibility(View.GONE);

    or Call

    the setChecked() of the radiobutton 1.

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

Sidebar

Related Questions

I have this group of radio buttons in which each of individual button has
I have radio buttons in HTML like this: <td> <input id=radio1 type=radio name=correctAnswer value=1>1</input>
I have two radio buttons that are disabled with javascript when the page loads.
I am having some trouble highlighting checkboxes and radio buttons that have been selected.
I have a DIV with a list of radio buttons and a 'selected search'
I have two radio buttons on my MVC form that I use to hide
I have three radio buttons with same name and different values.When I click the
I have two radio buttons next to each other, and even though each one
I have 2 radio buttons, what I want is if a user selects the
I have 2 radio buttons and I used mootool while loading as window.addEvent('domready', function()

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.