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来解除对话框。我的问题是,当单击自定义按钮时,我想取消对话栏。基本上,当单击按钮时,它将执行一些工作人员并取消对话框。我应该拨打哪种方法?
答案 0 :(得分:1)
试试这个
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();
}
});