AlertDialog vs Toast : Toast « UI « Android






AlertDialog vs Toast

  
//package com.jwetherell.pedometer.utilities;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.widget.Toast;

abstract class MessageUtilities {
    
    public static enum ConfirmationResult {YES,NO};
    
    public static void confirmUser( Context context, String msg,
                                    DialogInterface.OnClickListener yesClick, 
                                    DialogInterface.OnClickListener noClick){
        Builder alert = new AlertDialog.Builder(context);
        alert.setIcon(android.R.drawable.ic_dialog_alert)
             .setTitle("Confirmation")
             .setMessage(msg)
             .setPositiveButton(    "Yes", yesClick)
             .setNegativeButton("No", noClick)
             .show();
    }
    
    public static void helpUser(Context context, String msg) {
        Toast t = Toast.makeText(context, msg, Toast.LENGTH_LONG);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
    }
    
    public static void alertUser(Context context, String msg) {
        Toast t = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
    }

    public static void alertUserTop(Context context, String msg) {
        Toast t = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
        t.setGravity(Gravity.TOP, 0, 0);
        t.show();
    }
}

   
    
  








Related examples in the same category

1.Raise a Toast
2.Toast Message Demo
3.Using Toast.LENGTH_SHORT
4.Toast and Notification, vibrate and sound
5.Show Toast
6.Make Toast Text
7.Responsible for sending Toasts under all circumstances.
8.Toast.LENGTH_SHORT
9.Show long,short Toast
10.The Toast util class
11.show Toast in a Thread
12.Popup Debug Message