onCreateOptionsMenu called after onResume on JB 4.2

前端 未结 1 2086
無奈伤痛
無奈伤痛 2021-02-18 14:56

I have the following fragment in my application:

public class MyFragment extends SherlockListFragment implements LoaderManager.LoaderCallbacks {
           


        
相关标签:
1条回答
  • 2021-02-18 15:29

    I've used onPrepareOptionsMenu in this way to achieve what you are trying to do. (not tested but should give you an idea.)

    private boolean mIsLoading = true;
    
    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        refresh = (MenuItem) menu.findItem(R.id.menu_item_refresh);
        if (!mIsLoading) {
            refresh.setActionView(null);
        }
    }
    
    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        mAdapter.swapCursor(data);
        mIsLoading = false;
        getActivity().invalidateOptionsMenu();
    }
    
    0 讨论(0)
提交回复
热议问题