今日代码
public class MainActivity extends AppCompatActivity{
//CheckBox复选框
private CheckBox check1;
private CheckBox check2;
private CheckBox check3;
private CheckBox check4;
private CheckBox check5;
private String str="特殊情况:";
//提交按钮
private Button mBtnSubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//CheckBox复选框
check1=findViewById(R.id.instruction1);
check2=findViewById(R.id.instruction2);
check3=findViewById(R.id.instruction3);
check4=findViewById(R.id.instruction4);
check5=findViewById(R.id.instruction5);
//提交按钮
mBtnSubmit = findViewById(R.id.btn_submit);
mBtnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//复选框
if(check1.isChecked()){
str+=check1.getText()+",";
}
if(check2.isChecked()){
str+=check2.getText()+",";
}
if(check3.isChecked()){
str+=check3.getText()+",";
}
if(check4.isChecked()){
str+=check4.getText()+",";
}
if(check5.isChecked()){
str+=check5.getText()+",";
}
Toast.makeText(MainActivity.this,str,Toast.LENGTH_LONG).show();
}
}