I want to avoid that the AlertDialog.Builder is closed if an option is not selected, and probe removing the dialog.dismiss()
but the same when I click on the button accept without having selected an option closes, I want the AlertDialog to remain visible there and when you press the OK button without having selected an option that displays a Toast saying that you must select an option.
imageButtonAddNewClient.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String itemOptions[] = {"Cliente activo", "Cliente inactivo"};
new AlertDialog.Builder(NewClient.this, R.style.AlertDialogCustom)
.setTitle("Agregar nuevo cliente:")
.setSingleChoiceItems(itemOptions, posicionSeleccionadaStateClient, null)
.setCancelable(false)
.setNeutralButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
intent = new Intent(NewClient.this, ActivityNewClient.class);
posicionSeleccionadaStateClient = ((AlertDialog)dialog).getListView().getCheckedItemPosition();
if(posicionSeleccionadaStateClient == 0){
intent.putExtra("code", 0);
}else if(posicionSeleccionadaStateClient == 1){
intent.putExtra("code", 1);
}else{
Toast.makeText(NewClient.this, "Seleccione una opción.", Toast.LENGTH_SHORT).show();
}
startActivity(intent);
dialog.dismiss();
}
}).show();
}
});