Android程序:RadioGroup的用法(多选一)

    "wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/radioGroup">

        "wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb1"
            android:text="男"
            android:checked="true"/>
        "wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb2"
            android:text="女"/>


        
public class MainActivity extends Activity implements RadioGroup.OnCheckedChangeListener{
    private RadioGroup radioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        radioGroup.setOnCheckedChangeListener(this);

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rb1:
                Toast.makeText(MainActivity.this,"you are a boy",Toast.LENGTH_SHORT).show();
                break;
            case R.id.rb2:
                Toast.makeText(MainActivity.this,"you are a girl",Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }


        }
    }

你可能感兴趣的:(安卓备忘录)