Problems with listview context menu with spinner

Asked

Viewed 43 times

0

I’m having a problem opening a context menu in a listview that has a spinner. I registered my list on onCreate:

registerForContextMenu(lista);

I created the menu and added its Reader:

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    MenuItem remover = menu.add("Remover");
    remover.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return false;
        }
    });
}

But my list is an Adapter I created and I have a spinner on each line. If I press and hold anywhere else on the list the menu does not appear at all. But when I press and secure on top of the spinner the menu appears. But I do not want menu pro spinner but rather for the list item.

I did a search and recommended putting a setFocusable(false) in the spinner. Still I still have the problem. Someone knows how to fix this?

1 answer

1

I don’t know if this is the right way to do it but I found the solution and maybe it helps other people.

How to adapt it was I who created I entered in xml and the parent layout that is a Constraintlayout I added the following line:

android:descendantFocusability="blocksDescendants"

This solved my problem and now the list line was opening the context menu.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.