gpt4 book ai didi

java - 读取对话框中的用户选择

转载 作者:行者123 更新时间:2023-12-01 13:45:23 25 4
gpt4 key购买 nike

是否可以读取对话框中的用户操作?

示例:单击按钮 bttn1 时,将打开对话框。如果用户在对话框中单击No,则不会发生任何情况。如果用户单击 Yes,则 bttn1 变得不可用,并且 bttn2 将其状态从 setEnabled(false) 更改为 setEnabled(true).

一般问题,但我部分引用蓝牙设置 documentation其中使用了 startActivityForResult()

正如当前答案所提供的,它是关于使用 startActivityForResult()onActivityResult() 但我仍然不知道如何在这种情况下实现它。

我无法实现this来克服这样的问题。

最佳答案

不确定这是否是您想要的,但您可以创建一个对话框并监听正面和负面按钮的点击。

new AlertDialog.Builder(this)
.setMessage("Deny or Grant?")
.setNegativeButton("Deny", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
// Do something on deny click.
}
})
.setPositiveButton("Grant", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// Do something on grant click.
}
})
.create().show();

编辑:

要检测用户是否已授予或拒绝蓝牙权限,您应该重写 Activity 中的 onActivityResult 并检查 resultCode。来自 documentation :

A dialog will be displayed, requesting user permission to make the device discoverable, as shown in Figure 2. If the user responds "Yes," then the device will become discoverable for the specified amount of time. Your activity will then receive a call to the onActivityResult()) callback, with the result code equal to the duration that the device is discoverable. If the user responded "No" or if an error occurred, the result code will be RESULT_CANCELED.

关于java - 读取对话框中的用户选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20405008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com