android:对话框,取消按钮
我创建了一个自定义对话框,并插入了两个按钮,一个按钮称为发送,另一个按钮取消。
I have created a custom dialog, And I have inserted two buttons, one is called send, and the other cancel.
我想知道热键在按取消时关闭对话框吗?
I would like to know hot to close down the dialog when pressing cancel?
您是否正在使用AlertDialog.Builder?实现自定义对话框的方法有很多,但是假设您的发送按钮是肯定按钮或中性按钮,而取消按钮是否定按钮,您总是可以这样做。
Are you using the AlertDialog.Builder? There are lots of way of implementing a custom Dialog but assuming your "Send" button is a positive or neutral button and your "Cancel" button is a negative button you can always do this.
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == Dialog.BUTTON_NEGATIVE)
dialog.dismiss()
}
您也可以调用 dialog.cancel()如果要调用 DialogInterface.OnCancelListener 。
You can also call dialog.cancel() if you want to invoke the DialogInterface.OnCancelListener.
如果不是这种情况,则需要提供其他信息。
If this is not the case you need to supply additional information.