jinreal
jinreal

Reputation: 1555

combobox and edittext inside radiogroup

I'm trying to get layout as below:

|--r--|---c---|
|--r--|---t---|

the widgets at "r" position is radiobutton, at "c" is combobox and at "t" is edittext.

I wish:
When the first "r" is selected , the "c" is enabled and the "t" is disabled; When the second "r" is selected, the "c" is disabled and the "t" is enabled;

Is that possible? How?

Upvotes: 1

Views: 1695

Answers (2)

Eldhose M Babu
Eldhose M Babu

Reputation: 14510

Try this :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="10" >

<RadioGroup
    android:id="@+id/radioSex"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="5" >

    <RadioButton
        android:id="@+id/radioMale"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/radio_male" />

    <RadioButton
        android:id="@+id/radioFemale"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/radio_female" />
</RadioGroup>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="5"
    android:orientation="vertical" >

    <Spinner
        android:id="@+id/cmbName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/etName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text" />
</LinearLayout>

</LinearLayout>

In Code :

    RadioGroup rgp = (RadioGroup) findViewById(R.id.radioSex);
    final Spinner cmbName = (Spinner) findViewById(R.id.cmbName);
    final EditText etName = (EditText) findViewById(R.id.etName);
    rgp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.radioMale) {
                etName.setEnabled(false);
                cmbName.setEnabled(true);
            } else {
                etName.setEnabled(true);
                cmbName.setEnabled(false);
            }
        }
    });

Upvotes: 1

Shruti
Shruti

Reputation: 5591

  <TableLayout 

    <Table row>
    <LinearLayout orientation:horizontal

    <Radiogroup .....
    android:orientation="horizontal"

    />
    <Spinner ...
    />
</LinearLayout>
    </TableRow>

    <TableRow >
<LinearLayout orientation:horizontal
    <Radiogroup .....
    android:orientation="horizontal"

    />
    <EditText ..... />
</LinearLayout>
</TableRow>
</TableLayout>

Upvotes: 1

Related Questions