Android alertDialog

Programming
Tutor: None Selected Time limit: 3 Days

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();

}

}

}


Nov 30th, -0001
Why not replace the second if with a simple 'else'?

When you say it is not working, what is happening?
Jun 11th, 2013

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Nov 30th, -0001
...
Nov 30th, -0001
Dec 8th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer