Answer the question
In order to leave comments, you need to log in
Why doesn't the context menu open in the fragment?
I'm trying to create a context menu inside a fragment. I perform the following sequence of actions:
1) I create a resource directory and a menu file (context_menu.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/download"
android:title="Download"/>
<item android:id="@+id/hello"
android:title="Hello"/>
<item android:id="@+id/bye"
android:title="Bye"/>
</menu>
val button = view.findViewById<Button>(R.id.download_button)
registerForContextMenu(button)
button.setOnClickListener {
Toast.makeText(requireContext(), "Click", Toast.LENGTH_SHORT).show()
}
override fun onCreateContextMenu(
menu: ContextMenu,
v: View,
menuInfo: ContextMenu.ContextMenuInfo?
) {
super.onCreateContextMenu(menu, v, menuInfo)
requireActivity().menuInflater.inflate(R.menu.context_menu, menu)
}
Answer the question
In order to leave comments, you need to log in
it will work with a long press, judging by the documentation
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question