public class MainActivity extends Activity {
private Button mybut=null;
private TextView mytxt=null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.mytxt=(TextView) super.findViewById(R.id.mytxt);
//获取我们的按钮对象
this.mybut=(Button) super.findViewById(R.id.mybut);
//为我们的按钮添加事件
this.mybut.setOnClickListener(new OnClickListenerImp());
}
public class OnClickListenerImp implements OnClickListener{
public void onClick(View arg0) {
Dialog dialog=new AlertDialog.Builder(MainActivity.this)
.setTitle("删除对话框")
.setIcon(R.drawable.ic_launcher)
.setMessage("确认删除吗?")
//相当于点击确认按钮
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
MainActivity.this.mytxt.setText("删除成功");
}
})
//相当于点击取消按钮
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
MainActivity.this.mytxt.setText("取消删除");
}
})
.create();
dialog.show();
}
}
}