How to handle onContextItemSelected in a multi fragment activity?

前端 未结 11 2124
天命终不由人
天命终不由人 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:16

    If you are using adapters with listviews in your fragment this might help.

    public boolean onContextItemSelected(final MenuItem item) {
        final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    
        //Check if the context menu call came from the list in this fragment (needed for support for multiple fragments in one screen)
        if (info.targetView.getParent() != getView().findViewById(android.R.id.list))
            return super.onContextItemSelected(item);
    
        //Handle context menu item call
        switch (item.getItemId()) {
            ...
        }
    }
    

提交回复
热议问题