How to handle onContextItemSelected in a multi fragment activity?

前端 未结 11 2086
天命终不由人
天命终不由人 2020-11-29 17:26

I\'m currently trying to adapt my application to use the \"Compatibility Libraries for Android v4\" to provide the benefits of the usage of fragments even to Android 1.6 use

11条回答
  •  眼角桃花
    2020-11-29 18:00

    I liked the simple solution by Sergei G (based on Jake Wharton fix), but inverted because it is easier to add to several fragments:

    public boolean onContextItemSelected(android.view.MenuItem item) 
    {  
        if( getUserVisibleHint() == false ) 
        {
            return false;
        }
    
        // The rest of your onConextItemSelect code
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
     }
    

    After that, the code same as it was before.

提交回复
热议问题