我需要你的帮助。我有几个复选框,我希望在未选中任何复选框时显示一条消息,通知用户在 Toast 视图中选择至少 1 个复选框。这是我的代码,现在如果没有选中复选框,它会显示消息,但之后会显示另一条消息。
if(ketch.isChecked()==true){
result2.append("Ketchup"+"\n");
}
if(may.isChecked()==true){
result2.append("Mayonnaise"+"\n");
}
if(mus.isChecked()==true){
result2.append("Mustard"+"\n");
}
else{
Toast.makeText(MainActivity.this,"Please choose at least 1 topping!",Toast.LENGTH_SHORT).show();
}
Toast.makeText(MainActivity.this, "Name: "+name.getText()+"\n"+"Phone: "+phone.getText()+"\n"+"Address: " +address.getText()+"\n"+"Shape: "+sh.getText()+"\n"+"Cheese: "+ty.getText()+"\n"+"Toppings: "+"\n"+result.toString()+"Sauce: "+"\n"+result2.toString(), Toast.LENGTH_LONG).show();
}
});
}