I have the following fragment in my application:
public class MyFragment extends SherlockListFragment implements LoaderManager.LoaderCallbacks {
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();
}