首页 > 解决方案 > 如何创建带有消息“您确定要删除它吗?”的窗口

问题描述

我正在 Kotlin 中做一个应用程序,我希望能够从 Realtime Firebase 中删除内容,但在此之前询问用户他/她/他们是否确定这一点。这个想法是有一个小窗口询问,然后有 2 个按钮,一个取消,另一个从 Firebase 中删除信息。你能帮助我吗?

标签: androidkotlinfirebase-realtime-database

解决方案


您需要的是AlertDialogMaterialAlertDialogBu ​​ilder

已包含一个简单的解决方案供您参考:

val dialog = AlertDialog.Builder(this)
                    .setIcon(android.R.drawable.ic_delete)
                    .setTitle("Delete")
                    .setMessage("Proceed and Delete")
                    .setPositiveButton("Delete"){ dialog, which ->
                        //Call your Firebase Code/function to delete inside here
                    }.setNegativeButton("Cancel"){dialog, which ->

                       //You don't need this in your case and can skip it
                    }.create()
                    .show()

干杯,


推荐阅读