I am trying to do some checks within alertdialog
to see if certain conditions are met and let the user continue with the process. But when the user gives the download button (PositiveButton) makes the checks and leaves the alertdialog
are met or not, when what I want is that if you meet any condition do not close the alertdialog
.
The alertdialog
is the following:
And the code of alertdialog
is:
dialog.setTitle(getResources().getString(R.string.calendar_dialog_info));
dialog.setView(layout);
dialog.setCancelable(false);
dialog.setPositiveButton(getResources().getString(R.string.download), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
KeyValueArrayAdapter.KeyValue sel = (KeyValueArrayAdapter.KeyValue) spinner_cal.getSelectedItem();
String cuentaSel = sel.value;
long idsel = Long.parseLong(sel.key);
if(idsel != -1) {
if (Utiles.conexionDisponible(getApplicationContext())) {
String tipo = Constants.CALENDARIO_ALUMNO;//TODO saber que tipo hay que descargar
//pasar id calendario y tipo de calendario
ObtenerCalendario obtenerTask = new ObtenerCalendario( tipo, idsel);
obtenerTask.execute();
} else {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.no_conex), Toast.LENGTH_LONG).show();
}
dialog.cancel();
}else{
Toast.makeText(PantallaPersonalActivity.this, "No se ha seleccionado nada " , Toast.LENGTH_SHORT).show();
}
}
});
dialog.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Cancelar
dialog.cancel();
}
});
dialog.show();
EDITED :
The expected behavior is that when you click the download button, check if a calendar has been selected, if you have selected close the alertdialog
and call a AsyncTask
, but if not nothing has been selected I do not want the alertdialog
to be closed and show either a Toast
, SnackBar
or in the same alertdialog
that a calendar selects.