天天看點

确定取消經典之作——基礎編

讓我們看一下效果圖

<a target="_blank" href="http://blog.51cto.com/attachment/201102/144540470.jpg"></a>

package com.smart; 

import android.app.Activity; 

import android.app.AlertDialog; 

import android.content.DialogInterface; 

import android.os.Bundle; 

import android.view.View; 

import android.view.View.OnClickListener; 

import android.widget.Button; 

/** 

 * 不知道看的朋友,認識,如何,我覺得挺經典的按鈕之作 

 * 如有問題,請發自[email protected] 

 * */ 

public class Main extends Activity implements OnClickListener{ 

    /** Called when the activity is first created. */ 

    @Override 

    public void onCreate(Bundle savedInstanceState) { 

        super.onCreate(savedInstanceState); 

        setContentView(R.layout.main); 

        //得到按鈕ID 

        Button button=(Button)findViewById(R.id.button); 

        //進行監聽 

        button.setOnClickListener(this); 

    } 

    @Override//斷送确定與取消方法 

    public void onClick(View v) { 

        new AlertDialog.Builder(this).setIcon(R.drawable.question).setTitle("是否删除檔案").setPositiveButton("确定", new DialogInterface.OnClickListener() { 

            @Override 

            public void onClick(DialogInterface dialog, int which) { 

                new AlertDialog.Builder(Main.this).setMessage("檔案已删除").create().show(); 

            } 

        }).setNegativeButton("取消", new DialogInterface.OnClickListener() { 

                new AlertDialog.Builder(Main.this).setMessage("您選擇取消按鈕,檔案未被删除").create().show(); 

        }).show(); 

本文轉自 llb988 51CTO部落格,原文連結:http://blog.51cto.com/llb988/489541,如需轉載請自行聯系原作者