Solution 1 :
You are calling your dialog.show
inside your positiveButton click, thats why it will never work. Change it like this:
val builder =AlertDialog.Builder(activity)
builder.setTitle("Ausloggen")
builder.setMessage("Willst du dich wirklich ausloggen?")
builder.setPositiveButton("Abmelden",
{ dialogInterface: DialogInterface, i: Int ->
/* your signout logic which I believe is this one: RegistrateUser.getAuth()?.signOut()*/
})
})
builder.setNegativeButton("zurück", { dialogInterface: DialogInterface, i: Int -> })
builder.show()
Let me know if it works!
Problem :
I try to have an alert box on my Fragment. My goal ist to logout a user. Before the user is logged out he hast to confirm it via the alert box.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val builder =AlertDialog.Builder(activity)
builder.setTitle("Ausloggen")
builder.setMessage("Willst du dich wirklich ausloggen?")
builder.setPositiveButton("Abmelden",
{ dialogInterface: DialogInterface, i: Int -> //Code zum Ausloggen })
builder.setNegativeButton("zurück", { dialogInterface: DialogInterface, i: Int -> })
builder.show()
})
RegistrateUser.getAuth()?.signOut()
startActivity(Intent(activity,LoginActivity::class.java))
}
Thats the code so far but it doesnt work. What did i do wrong?
Comments
Comment posted by einUsername
Any error? Does it compile? What happens if you click it?
Comment posted by jorah
Yes it works. i put the signout logic where it belongs. Thank you