Android UI How to - Alert with AlertDialog








Question

We would like to know how to alert with AlertDialog.

Answer

import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;
//  ww w  .j a  v  a 2 s.c om
public class Main {

  static void complain(Activity act, String Tag, String message) {
    alert(act, Tag, "Error: " + message);
  }

  static void alert(Activity act, String Tag, String message) {
    AlertDialog.Builder bld = new AlertDialog.Builder(act);
    bld.setMessage(message);
    bld.setNeutralButton("OK", null);
    Log.d(Tag, "Showing alert dialog: " + message);
    bld.create().show();
  }
}