KB-20071210-033

From Triled Wiki

Jump to: navigation, search

Code and layout are taken from original post

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  id="@+id/ll">
</LinearLayout>

Java code:

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class Test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        LinearLayout ll = (LinearLayout)findViewById(R.id.ll);

        RadioGroup rg = new RadioGroup(this);
        rg.setLayoutParams(new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        ll.addView(rg);

        RadioGroup.LayoutParams rlp = new RadioGroup.LayoutParams(
            RadioGroup.LayoutParams.WRAP_CONTENT,
            RadioGroup.LayoutParams.WRAP_CONTENT);

        RadioButton foo = new RadioButton(this);
        foo.setText("foo");
        foo.setLayoutParams(rlp);
        rg.addView(foo);

        RadioButton bar = new RadioButton(this);
        bar.setText("bar");
        bar.setLayoutParams(rlp);
        rg.addView(bar);

        RadioButton baz = new RadioButton(this);
        baz.setText("baz");
        baz.setLayoutParams(rlp);
        rg.addView(baz);
    }
};

Unexpected behaviour: The resulting radio buttons fail to be mutually exclusive.

[edit] See also

Personal tools