Search code examples
kotlinandroid-alertdialog

What context should I give to AlertDialog.Builder?


I have a problem with AlertDialog.Builder, I am trying to find the right context to give to builder = AlertDialog.Builder(this) but I keep having this error message Type mismatch. Required: Context Found: ProfilFragment

import : androidx.appcompat.app.AlertDialog

I really don't know at this point what context to use instead. Thank you


Solution

  • You can access context from a fragment by using requireContext(). So pass requireContext() instead of this in the AlertDialog.Builder