Home > Mobile >  What context should I give to AlertDialog.Builder?
What context should I give to AlertDialog.Builder?

Time:11-04

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

CodePudding user response:

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

  • Related