I have a DialogFragment that I want to show when clicking on an item inside a Recycler View. Here are my files:
DialogFragment.kt:
class TaskDialogFragment:DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
var rootView: View = inflater.inflate(R.layout.task_dialog, container, false)
return rootView
}
}
RecyclerViewAdapter.kt:
class RecycleViewAdapter(): RecyclerView.Adapter<RecycleViewAdapter.ViewHolder>() {
private lateinit var dao: TaskDao
private lateinit var dialogFragment: TaskDialogFragment
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
init {
itemView.setOnClickListener { v: View ->
// this is where I want my dialogFragment to be opened from
dialogFragment = TaskDialogFragment()
dialogFragment.show(supportFragmentManager, "taskDialog")
}
}
}
I have tried following the steps shown here https://developer.android.com/guide/fragments/dialogs but I get an error saying Unresolved Reference: supportFragmentManager
.
How would I open this dialog from the recycler view? Any tips would be appreciated.