Android alertDialog

User Generated

nycunfvy

Programming

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

}

}

}


User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Why not replace the second if with a simple 'else'?

When you say it is not working, what is happening?


Anonymous
Awesome! Perfect study aid.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags