FileDocCategorySizeDatePackage
RadioGroup1.javaAPI DocGoogle Android v1.5 Example2632Sun Nov 11 13:01:04 GMT 2007com.google.android.samples.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 icicle)

        super.onCreate(icicle);

        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);