如何在android中获取对话框 [英] how do get dialog box in android

查看:92
本文介绍了如何在android中获取对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 public void onClick(查看arg0){
// TODO自动生成的方法stub
Dialog d = new Dialog(null);
d.setTitle(hi);
d.show();

}
});



i使用此代码,但当我点击按钮时,它会显示错误。

解决方案

您需要在对话框中使用 Builder 类来创建对话框。



这可能对你有用;



  new  AlertDialog.Builder( this 
.setTitle( 对话标题
.setMessage( 你想做吗?这个?
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框, int 哪个) {
// 用户点击是的代码是
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框, int ){
// 用户点击时的代码否
}
})
.show();





你可以在那里连接其他一些电话来设置像其他东西一样的东西(或者不设置例如没有按钮)。



希望这会有所帮助,

Fredrik


参考: android-custom-dialog-example / [ ^ ]

public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Dialog d = new Dialog(null);
				d.setTitle("hi");
				d.show();

			}
		});


i use this code but when i click the button it displays the error.

解决方案

You'll want to use the Builder class on the dialog to create your dialog.

This might work for you;

new AlertDialog.Builder(this)
    .setTitle("Dialog Title")
    .setMessage("Do you want to do this?")
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Code for when user clicks Yes
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Code for when user clicks No
    }
     })
    .show();



You can chain loads of other calls there to set things like icon other things (or not set No button for example).

Hope this helps,
Fredrik


Refer: android-custom-dialog-example/[^]


这篇关于如何在android中获取对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆