Breaking News
Home / Android / Android Snippets / How to show an Alert Dialog in Android?

How to show an Alert Dialog in Android?

  1. public static void showDialog(final Context context, final String title, final String message) {
  2.  
  3.  
  4.   MainThread.run(context, new Runnable() {
  5.   @Override
  6.   public void run() {
  7.   AlertDialog.Builder builder = new AlertDialog.Builder(context);
  8.   builder.setTitle(title);
  9.   builder.setMessage(message);
  10. DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() {
  11.                                         @Override
  12.         public void onClick(DialogInterface dialog, int which) {
  13.                                 dialog.dismiss();
  14.                         }
  15.                 };
  16.         builder.setPositiveButton("Ok", buttonListener);
  17.         builder.show();
  18.      }
  19.   });
  20. }
[pb_builder]

Check Also

How to check if an Android device can connect to Internet?

The following code snippet shows how to check if an Android device can connect to …

Advertisment ad adsense adlogger