如何在android中获得DialogResult?

如何在android中获得DialogResult?,第1张

概述我想用两个按钮’YES’和’NO’创建一个DialogAlert.我想在布尔变量中捕获Dialog的结果.假设用户单击“YES”按钮,则DialogResult应返回true值,如果用户单击“NO”按钮,则DialogResult应返回False值.请帮我解决这个问题.提前致谢. 我会使用AlertDialog( see documentation here).如果你有自己的类DialogResu 我想用两个按钮’YES’和’NO’创建一个Dialogalert.我想在布尔变量中捕获Dialog的结果.假设用户单击“YES”按钮,则DialogResult应返回true值,如果用户单击“NO”按钮,则DialogResult应返回False值.请帮我解决这个问题.提前致谢.解决方法 我会使用AlertDialog( see documentation here).如果你有自己的类DialogResult,代码可能如下所示:

DialogResult result = new DialogResult(); AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setMessage("Are you sure you want to exit?")   .setCancelable(false)   .setPositivebutton("Yes",new DialogInterface.OnClickListener() {       public voID onClick(DialogInterface dialog,int ID) {            // User clicked Yes: set the value to your result class here. E.g:            MyActivity.result.setValue(true);       }   })   .setNegativebutton("No",int ID) {            // User clicked No: set the value to your result class here. E.g:             MyActivity.result.setValue(false);       }   });AlertDialog alert = builder.create();
总结

以上是内存溢出为你收集整理的如何在android中获得DialogResult?全部内容,希望文章能够帮你解决如何在android中获得DialogResult?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1121799.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存