gpt4 book ai didi

java - Android,警报对话框。单击时如何访问其标题?

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

在某些时候,我需要将向用户提问的警报对话框排队,等待他/她一一回答。代码类似于:

for (int i=0; i<SomeValue; i++)
{
Msg = "Do you want to add " + mylist.get(i) + " to the system?";
AlertDialog ADB = new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("New document " + mylist.get(i))
.setMessage(Msg)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// Function to develop

}
})
.setNegativeButton("Ignore", null)
.show();
}

那么,开发 onClick 函数时:我如何知道哪个是关联的 Alertdialog?例如,我如何从onClick函数中获知当前Alertdialog的标题是什么?

最佳答案

现在,您无法访问默认标题,因此您需要使用以下方式设置标题:setCustomTitle(View v) - 只需将其设置为带有标题的简单布局 XML 文件即可 TextView 就在其中。

onClick() 方法中将 DialogInterface 转换为 AlertDialog,如下所示:

((AlertDialog)dialog)

现在您可以像这样访问任何您想要的内容:

((AlertDialog)dialog).findViewById(R.id.YOUR_TITLE_TEXTVIEW_ID).getText()

关于java - Android,警报对话框。单击时如何访问其标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12736587/

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