main.xml代码下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<Button
android:id="@+id/mybtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="删除" />

</LinearLayout>


.java代码如下:

package org.lxh.demo;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Hello extends Activity {
private Button btn = null;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // 生命周期方法
super.setContentView(R.layout.main); // 设置要使用的布局管理器
this.btn = (Button) super.findViewById(R.id.mybtn);
this.btn.setOnClickListener(new OnClickListernerImpl());

}

private class OnClickListernerImpl implements OnClickListener {

public void onClick(View v) {
Dialog dialog = new AlertDialog.Builder(Hello.this)
.setIcon(R.drawable.pic_m)
.setTitle("确定删除?")
.setMessage("您确定要删除此信息?")
.setPositiveButton("删除",
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface arg0,
int arg1) {

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

public void onClick(DialogInterface arg0,
int arg1) {

}
}).create();

dialog.show();
}

}
}

效果如下:

Dialog确定和删除按钮_android