kazbeel
kazbeel

Reputation: 1436

Create on Android a Context Menu when selecting an Item from a Popup Menu

I am developing simple application similar to this one

Application with Popup Menu

Now, I would like to show a Context Menu (as extra options, see example below) when selecting only element One.

Example of Context Menu

The main problem I am facing right now is that I have no idea how and where to register the context menu (registerForContextMenu). What should be the view in this case?

Any help is appreciated.

Thanks in advance!

Upvotes: 0

Views: 2316

Answers (2)

user15173649
user15173649

Reputation:

use this simple code in Kotlin

val wrapper: Context = ContextThemeWrapper(context, R.style.popup)
        val popup = PopupMenu(wrapper, holder.binding.imgMenu)
        popup.inflate(R.menu.walk_in_patient_menu)
        popup.setOnMenuItemClickListener(object : PopupMenu.OnMenuItemClickListener {
            override fun onMenuItemClick(item: MenuItem?): Boolean {
                when (item?.getItemId()) {
                    R.id.check_id ->
                        return true
                    else -> return false
                }
            }

        })
        popup.show()

Upvotes: 1

kazbeel
kazbeel

Reputation: 1436

I have found an alternative to Context Menus by using List Dialog. This way is much easier that the one I considered.

Upvotes: 0

Related Questions