gpt4 book ai didi

Android AlertDialog Builder 更好的代码

转载 作者:行者123 更新时间:2023-11-30 01:21:13 25 4
gpt4 key购买 nike

我得到了下面的代码来在 Android 中生成一个警告对话框:

new AlertDialog.Builder(actContainer).
setIcon(R.mipmap.ic_attach_file_black_24dp).
setTitle(strTitle).
setMessage(Html.fromHtml(strHtml)).
setCancelable(false).
setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Log.i("OptimGeek", "prrrrrrr . . .")
}
}
).
show()

它在 groovy 中,实际上它工作得很好,如何改进“setPossitiveButton”以避免内部类?

提前致谢

最佳答案

使用 SAM 类型强制或 Implicit Closure Coercion :

new AlertDialog.Builder(actContainer).
setIcon(R.mipmap.ic_attach_file_black_24dp).
setTitle(strTitle).
setMessage(Html.fromHtml(strHtml)).
setCancelable(false).
setPositiveButton("OK", { DialogInterface dialogInterface, int i ->
Log.i("OptimGeek", "prrrrrrr . . .")
} as DialogInterface.OnClickListener).
show()

关于Android AlertDialog Builder 更好的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37082305/

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