Description
Hi, what's wrong with this code, the second if doesn't work
@SuppressWarnings("deprecation")
public void showAnulacao(View v) {
String result = "Os dias anulados foram:";
Double totalAmount = 0.0;
for (Refeicao p : boxAdapter.getBox()) {
if (p.selected) {
result += "\n" + p.dia;
totalAmount += p.preco;
AlertDialog alertDialog = new AlertDialog.Builder(CantinaDiurnoActivity.this).create();
alertDialog.setTitle("Informação");
alertDialog.setMessage(result + "\n" + "Creditamos-lhe: " + totalAmount + "€");
alertDialog.setIcon(R.drawable.tick);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alertDialog.show();
}
if(!p.selected){
AlertDialog alertDialog = new AlertDialog.Builder(CantinaDiurnoActivity.this).create();
alertDialog.setTitle("Erro!");
alertDialog.setMessage("Não efetuou nenhuma seleção!");
alertDialog.setIcon(R.drawable.delete);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alertDialog.show();
}
}
}
Explanation & Answer
Why not replace the second if with a simple 'else'?
When you say it is not working, what is happening?
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
Fences
by August Wilson
Black Beauty
by Anna Sewell
The Splendid and The Vile
by Erik Larson
A Brief History of Humankind Sapiens
by Yuval Noah Harari
All the Kings Men
by Robert Penn Warren
The Call of the Wild
by Jack London
The Picture of Dorian Gray
by Oscar Wilde
Of Mice and Men
by John Steinbeck
Ezperanza Rising
by Pam Muñoz Ryan