android - 如何创建带有消息“您确定要删除它吗?”的窗口
问题描述
我正在 Kotlin 中做一个应用程序,我希望能够从 Realtime Firebase 中删除内容,但在此之前询问用户他/她/他们是否确定这一点。这个想法是有一个小窗口询问,然后有 2 个按钮,一个取消,另一个从 Firebase 中删除信息。你能帮助我吗?
解决方案
您需要的是AlertDialog或MaterialAlertDialogBu 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()
干杯,
推荐阅读
- c# - Why are several executions of an eventhandler triggered from the same thread if I am invoking the event from a different thread each time?
- ios - 无法与 UIView 中的任何内容进行交互
- database - 无法在 Windows 上使用 Psycopg2 连接到 Postgres
- django - 将一个表单域的值替换为另一个
- javascript - 无论如何,使用最后一个参数反应事件处理程序
- python - Vim for Python 中的自动缩进
- java - 父类中不存在被覆盖方法中的变量
- swift - 在 UIView 上添加两个不同颜色的阴影?
- sql - 获取特定列的总和以及最后一行中另一列的值
- flutter - 如何获得通过的总时间颤动 - 使用计时器颤动