Code Snippet 10 of /src/com/examples/tipcalc/Tipster.java
  1. /**
  2.  * Shows the error message in an alert dialog
  3.  *
  4.  * @param errorMessage
  5.  *            String the error message to show
  6.  * @param fieldId
  7.  *            the Id of the field which caused the error.
  8.  *            This is required so that the focus can be
  9.  *            set on that field once the dialog is
  10.  *            dismissed.
  11.  */
  12. private void showErrorAlert(String errorMessage,
  13.     final int fieldId) {
  14.     new AlertDialog.Builder(this).setTitle("Error")
  15.     .setMessage(errorMessage).setNeutralButton("Close",
  16.             new DialogInterface.OnClickListener() {
  17.                 @Override
  18.                 public void onClick(DialogInterface dialog,
  19.                         int which) {
  20.                     findViewById(fieldId).requestFocus();
  21.                 }
  22.             }).show();
  23. }
Tutorials