FileDocCategorySizeDatePackage
RadioGroup1.javaAPI DocAndroid 1.5 API2671Wed May 06 22:41:08 BST 2009com.example.android.apis.view

RadioGroup1

public class RadioGroup1 extends android.app.Activity implements RadioGroup.OnCheckedChangeListener, View.OnClickListener

Fields Summary
private android.widget.TextView
mChoice
private android.widget.RadioGroup
mRadioGroup
Constructors Summary
Methods Summary
public voidonCheckedChanged(android.widget.RadioGroup group, int checkedId)

        String selection = getString(R.string.radio_group_selection);
        String none = getString(R.string.radio_group_none);
        mChoice.setText(selection +
                (checkedId == View.NO_ID ? none : checkedId));
    
public voidonClick(android.view.View v)

        mRadioGroup.clearCheck();
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        setContentView(R.layout.radio_group_1);
        mRadioGroup = (RadioGroup) findViewById(R.id.menu);

        // test adding a radio button programmatically
        RadioButton newRadioButton = new RadioButton(this);
        newRadioButton.setText(R.string.radio_group_snack);
        newRadioButton.setId(R.id.snack);
        LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
                RadioGroup.LayoutParams.WRAP_CONTENT,
                RadioGroup.LayoutParams.WRAP_CONTENT);
        mRadioGroup.addView(newRadioButton, 0, layoutParams);

        // test listening to checked change events
        String selection = getString(R.string.radio_group_selection);
        mRadioGroup.setOnCheckedChangeListener(this);
        mChoice = (TextView) findViewById(R.id.choice);
        mChoice.setText(selection + mRadioGroup.getCheckedRadioButtonId());

        // test clearing the selection
        Button clearButton = (Button) findViewById(R.id.clear);
        clearButton.setOnClickListener(this);