Monday, March 12, 2012

Alert Dialog


 For showing  Alert Dialog in your Activity....

import this...

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;




Call this method for showing alert dialog 

void showDialog(){

          AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Title");    // Set the title displayed in the Dialog.
            builder.setMessage("Message");  // Set the message to display.
// Set a listener to be invoked when the neutral button of the dialog is pressed.
            builder.setNeutralButton("Ok", new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Stop the activity
                finish();   // Call this when your activity is done and should be closed. The ActivityResult is 
// propagated back to whoever launched you via onActivityResult().

            }
          });
            builder.show(); // Creates a AlertDialog with the arguments supplied to this builder and show()'s the dialog.

      }




ScreenShot :



No comments: