单项选择

需要用到的是RadioGroup和RadioButton,RadioButton放在RadioGroup里面:
public class SingleChoice extends AppCompatActivity {

private Button singleChoice;
private RadioButton rbA;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_choice);
    rbA = (RadioButton)findViewById(R.id.rbA);

    singleChoice = (Button)findViewById(R.id.btnSubmit);
    singleChoice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (rbA.isChecked()){
                Toast.makeText(SingleChoice.this,"所选是正确的",Toast.LENGTH_SHORT).show();

            }else{

                Toast.makeText(SingleChoice.this,"所选是错误的",Toast.LENGTH_SHORT).show();

            }

        }
    });
}

}

你可能感兴趣的:(单项选择)