In my Android application when an user touch an overlayItem on the map for more than 1.5 seconds an AlertDialog appear. I need user’s answer (alertDialogResult) to either keep the overlayItem or remove it from the map. However, after the AlertDialog inner-class get called, the outer-class continue it execution and at that point I do not have user’s answer.
Any suggestions? Any alternative to AlertDialog?
final Boolean alertDialogResult = false;
if ( ( pressEndTime - pressStartTime ) > 1500 ) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder( mapView.getContext() );
alertDialog.setTitle( "Warning!" );
alertDialog.setMessage("Do you want to delete the selected overlayItem?");
alertDialog.setCancelable(false);
alertDialog.setIcon(R.drawable.ic_dialog_alert);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
alertDialogResult = true;
}
});
alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alertDialog.show();
longPress = true;
if ( alertDialogResult == true ) {
AndroidMainActivity.sendDeleteOverlayRequest(mapView, overlayItemId);
}
Why do you need alertDialogResult flag, you can move
to onClick of positiveButton
Edit: Your AlertDialog will not wait for user Interatction after it has been Initialized. That is why there is callback for Onclick.