I'm doing an app in Kotlin where I want to be able to delete things from Realtime Firebase, but before doing that ask the user if he/she/they is sure of that. The idea is having a little window asking that and then having 2 buttons, one that cancels and another that deletes the information from Firebase. Can you help me?
Asked
Active
Viewed 66 times
1
-
1You can use an alert dialog to do this. Checkout this [question](https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android). – Ashique Bava Aug 04 '21 at 10:46
-
1Hey Mariana, what have you tried so far in code for that? – Alex Mamo Aug 04 '21 at 10:48
-
Hi @AlexMamo! I'm currently trying to do a AlertDialog, it apperently will work – Marina R Albuquerque Aug 04 '21 at 11:06
1 Answers
2
What you need is an AlertDialog or a MaterialAlertDialogBuilder
Have included a simple solution for your reference:
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()
Cheers,

Tonnie
- 4,865
- 3
- 34
- 50