Using FragmentManager In RecyclerView Adapter Click Event

With the deprecation of FragmentManager, Android Studio desn't provide any code suggestions for the deprecated code.

The problem is fragmentManager in val manager = (holder.itemView.context as Activity).fragmentManager as it returns this error:

'getter for fragmentManager: FragmentManager!' is deprecated. Deprectaed in Java

I'm already using import but the issuee still doesn't go away. Also, I've already seen this question, but it's not clear on what should be used instead in Kotlin.

holder.myButton.setOnClickListener {
    val dialog = MyDialogFragment()
    val manager = (holder.itemView.context as Activity).fragmentManager, "example")


According to the documentation, you should get the support manager instead. You'll just have to cast the context to FragmentActivity instead of Activity, like this:

val manager = (holder.itemView.context as FragmentActivity).supportFragmentManager

EDIT: Make sure that MyDialogFragment extends, not Your Activity should also extend AppCompatActivity (or at least FragmentActivity) to make it work correctly.