让我们看一下效果图

 

确定取消经典之作——基础编_休闲

 

 

 

  1. package com.smart; 
  2.  
  3. import android.app.Activity; 
  4. import android.app.AlertDialog; 
  5. import android.content.DialogInterface; 
  6. import android.os.Bundle; 
  7. import android.view.View; 
  8. import android.view.View.OnClickListener; 
  9. import android.widget.Button; 
  10. /** 
  11.  * 不知道看的朋友,认识,如何,我觉得挺经典的按钮之作 
  12.  * 如有问题,请发自llb988@126.com 
  13.  * */ 
  14. public class Main extends Activity implements OnClickListener{ 
  15.     /** Called when the activity is first created. */ 
  16.     @Override 
  17.     public void onCreate(Bundle savedInstanceState) { 
  18.         super.onCreate(savedInstanceState); 
  19.         setContentView(R.layout.main); 
  20.         //得到按钮ID 
  21.         Button button=(Button)findViewById(R.id.button); 
  22.         //进行监听 
  23.         button.setOnClickListener(this); 
  24.     } 
  25.  
  26.     @Override//断送确定与取消方法 
  27.     public void onClick(View v) { 
  28.         new AlertDialog.Builder(this).setIcon(R.drawable.question).setTitle("是否删除文件").setPositiveButton("确定"new DialogInterface.OnClickListener() { 
  29.              
  30.             @Override 
  31.             public void onClick(DialogInterface dialog, int which) { 
  32.                 new AlertDialog.Builder(Main.this).setMessage("文件已删除").create().show(); 
  33.             } 
  34.         }).setNegativeButton("取消"new DialogInterface.OnClickListener() { 
  35.              
  36.             @Override 
  37.             public void onClick(DialogInterface dialog, int which) { 
  38.                 new AlertDialog.Builder(Main.this).setMessage("您选择取消按钮,文件未被删除").create().show(); 
  39.             } 
  40.         }).show(); 
  41.     }