RadioGroup实现多选一的功能

1.先布局一个RadioGroup,在这个下面布局你需要的RadioButton(的个数)

2.在java文件中,申明并定义一个RadioGroup,给RadioGroup注册监听器

rg=(RadioGroup)findViewById(R.id.radioGroup);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.radioButton2:
                Toast.makeText(MainActivity.this,"你选择了商户模式",Toast.LENGTH_SHORT).show();
            case R.id.radioButton3:
                Toast.makeText(MainActivity.this,"你选择了跑腿模式",Toast.LENGTH_SHORT).show();
            default:
                break;
        }
    }
});

你可能感兴趣的:(Android)