android基础AlertDialog使用

android中创建对话框相对来说比较简单new一个AlertDialog.Builder,然后设置它的一些信息比如显示内容,标题,是否可以通过返回键取消对话框,确定按钮,取消按钮等等。

image

 

     new AlertDialog.Builder(EX03_12.this) 
.setTitle(R.string.app_about)
.setMessage(R.string.app_about_msg)
.setCancelable(false)
.setPositiveButton(R.string.str_ok,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int i)
{
}
})
.setNegativeButton(R.string.str_cancel,
new DialogInterface.OnClickListener()
{

@Override
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
finish();
}
}).show();



setCancelable(false)表示不可以通过手机上的返回键取消对话框,.setPositiveButton(),.setNegativeButton()分别设置确定按钮的事件和取消按钮的事件。

posted @ 2012-02-19 12:29  小文字  阅读(2126)  评论(0编辑  收藏  举报