android:对话框,取消按钮 [英] android: Dialog, cancel button

查看:151
本文介绍了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.

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

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