In one of my Fragments I have a method I call from the parent Activity. The method is nothing special, it simply scrolls my ListView to a position.
public void scrollToSomething() {
mListView.smoothScrollToPosition(The position I supply);
}
When I call this method initially, it works just like I expect, but when I rotate my device and call it again, I throw a NullPointerException from my ListView. I'm very much lost as to why this is happening. I've tried calling setRetainInstance(true). I've tried checking to see if my ListView is null before I call the method and if it is, then I initialize it again, but this does not work either. I've tried changing my onCreateView in a few different ways, thinking maybe something is going wrong there.
onCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/* The View for the fragment's UI */
final ViewGroup mRootView = (ViewGroup)inflater.inflate(R.layout.fragment_list_base,
container, false);
/* Initialize our ListView */
mListView = (ListView)mRootView.findViewById(R.id.fragment_list_base);
return mRootView;
}
The Fragment is attached to a ViewPager using a simple FragmentStatePagerAdapter. I've tried carefully looking through the onDestroy methods of my Fragment and the parent Activity to see if I'm calling something that may cause the error, but nothing stands out. I'm not sure if what I'm experiencing is some sort of bug, or if I'm just overlooking something. Any help or advice would be huge. I'm not entirely sure what else to add because I'm just pretty lost as why this is happening, but if anyone has a question, I'll post any code you may see fit.