Ruby on Rails & Android
[Android] Add a modal dialog
Here is the code to add something like in this image : a dialog (pop-up) with buttons in Android.
Normally, the user may come back to your application with the “back” button. I wanted it to be a dead-end dialog. My aim was to close the application if there is no Internet connexion at all.
In this example, I set a modal AlertDialog with a title, a message, and an “OK” button, which will close the application (my current activity and a service).
What makes it modal, which means the user can not go back to the application without pushing the “OK” button, is the setCancelable(boolean) function.
AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("No connection"); alertDialog.setMessage("Oxydroid a besoin d'une connexion à Internet. Veuillez vérifier vos paramètres."); alertDialog.setCancelable(false); alertDialog.setButton("OK",new OnClickListener() { public void onClick(DialogInterface dialog, int which) { stopService(new Intent(Oxydroid.this, PlayerService.class)); Oxydroid.this.finish(); } }); alertDialog.show(); |
| Print article | This entry was posted by Alexandre Gherschon on December 18, 2009 at 12:20 PM, and is filed under Android, Java. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

