I am fetching some data from SQLite in a Fragment using a CursorLoader. The initLoader() for this is executed in onActivityCreated()...
public class MyFragment extends Fragment implements LoaderCallbacks
{
MenuItem menuItemOne;
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
getLoaderManager().initLoader(0, null, this);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
inflater.inflate(R.menu.myMenu, menu);
menuItemOne = menu.findItem(R.id.menuItemOne);
}
@Override
public void onLoadFinished(Loaderloader, Cursor cursor)
{
menuItemOne.doSomething();
}
}
The above code is simplified for ease of reading. Here is my problem...
- On a Nexus S, there is no problem.
- On a Nexus 7, a null pointer arises in onLoadFinished. menuItemOne is null here.
The Nexus S is using Android 4.1.2 and the Nexus 7 is using Android 4.2.2.
- Should I be running initLoader() elsewhere?
- Do you think there is a bug/difference in the Android versions?
.
stackoverflow.comm
No comments:
Post a Comment