如何在对话框中自定义按钮dismis定制对话框? [英] How to dismis custom dialog from a custom button in dialog?
本文介绍了如何在对话框中自定义按钮dismis定制对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi there,
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
inviteView = getLayoutInflater().inflate(R.layout.invite_dialog, null);
builder.setView(inviteView);
sendSmsButton = (Button) inviteView.findViewById(R.id.sendSMSButton);
sendEmailButton = (Button) inviteView.findViewById(R.id.sendEmailButton);
builder.setTitle(R.string.invite_callrz_title);
sendSmsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
sendEmailButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
builder.setNegativeButton(R.string.cancelItem,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
return builder.create();
}
我有2个按钮上它。我也使用默认nagativeButton到dismis对话框自定义布局。我的问题是,我想dismis对话栏被点击自定义按钮时。基本上,当单击该按钮时,它会做一些工作人员和dismis对话框。我应该调用哪个方法?
I have a custom layout with 2 buttons on it.I also use a default nagativeButton to dismis the dialog. My question is I would like to dismis the dialog bar when the custom buttons are clicked. Basically, when the button is clicked, it will do some staff and dismis the dialog. which method I should call?
推荐答案
试试这个
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog alertDialog;
alertDialog = builder.create();
sendSmsButton = (Button) builder.findViewById(R.id.sendSMSButton);
sendSmsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
}
});
这篇关于如何在对话框中自定义按钮dismis定制对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文