Android open ContextMenu on short click + pass item clicked details

后端 未结 6 622
不思量自难忘°
不思量自难忘° 2020-12-03 03:19
 lv.setOnItemClickListener(new OnItemClickListener() {
             @Override
          public void onItemClick(AdapterView parent, View view, int position,         


        
6条回答
  •  离开以前
    2020-12-03 03:37

    I was able to open a context menu on button click with the following code:

    public void onButtonClickEvent(View sender)
    {
        registerForContextMenu(sender); 
        openContextMenu(sender);
        unregisterForContextMenu(sender);
    }
    

    Just set the onClick property of the button to onButtonClickEvent. A long click won't trigger the context menu, since it is unregistrered right after it is shown.

提交回复
热议问题