确定取消经典之作——基础编
让我们看一下效果图
- 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() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- new AlertDialog.Builder(Main.this).setMessage("您选择取消按钮,文件未被删除").create().show();
- }
- }).show();
- }
- }
本文转自 llb988 51CTO博客,原文链接:http://blog.51cto.com/llb988/489541,如需转载请自行联系原作者