When I try to override the onCreateDialog method of androidx.fragment.app.DialogFragment I get the following error: 'onCreateDialog overrides nothing'.
According to developer.android.com I should be able to override it as it's defined as open.
I am using the following code
import android.app.AlertDialog
import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import androidx.fragment.app.DialogFragment
class MyDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle): Dialog {
return activity?.let {
val builder = AlertDialog.Builder(it)
builder.setMessage("Yes or no?")
.setPositiveButton("yes",
DialogInterface.OnClickListener { dialog, id ->
// yes
})
.setNegativeButton("no",
DialogInterface.OnClickListener { dialog, id ->
// no
})
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}
}
What's going on here?