Wednesday, 22 February 2012

Learn Dialog

package com.project1;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;
public class AlertdemoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        ad.setMessage("Are you sure you want to proceeed")
        .setCancelable(false)
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  
   @Override
   public void onClick(DialogInterface dialog, int which) {
    Toast.makeText(AlertdemoActivity.this, "Yes, we can proceed", Toast.LENGTH_SHORT).show();
   
   }
  })
        .setNegativeButton("No", new DialogInterface.OnClickListener() {
  
   @Override
   public void onClick(DialogInterface dialog, int which) {
    Toast.makeText(AlertdemoActivity.this,"Thanks and we are exiting", Toast.LENGTH_SHORT).show();
   
   }
  });
         AlertDialog alert = ad.create();
         ad.show();
       
       
        }   
       
       
       
       
    }

No comments:

Post a Comment