After changing the orientation, my activity with the viewpager, which is a list / part view, is recreated and reset if I select an item in the list.
I don't want to bother you with all the details (there is a nullpointerexception exception, because the text view referenced in onCreateView () is null). My question is: how does the ViewPager display 2 pages with a fragment in each of them, without even calling them onCreateView ()?
How does it work after starting the application before turning on the device?
I only have 2 pages / snippets. But I saw with the debugger that 4 fragments are created when this activity is recreated. Do you know why and where is this documented?
Any solution? Thanks in advance for your help. I get lost here, because I myself do not control the fragments, the viewer does.
===========
Update: please find additional requested information.
public class DetailFragment extends Fragment {
TextView mDetailTV;
private String getData() {
ViewPagerActivity activity = (ViewPagerActivity)getActivity();
return( activity.detailArray[activity.mPosition] );
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_detail_fragment, container, false);
mDetailTV = (TextView)view.findViewById(R.id.detailTV);
displayDetail(getData());
return view;
}
void displayDetail(String data) {
mDetailTV.setText(data);
}
and fragments of the list and parts are created and transferred to the Pager Adapter as follows:
mListFragment = new ListFragmentt();
mDetailFragment = new DetailFragment();
mPagerAdapter = new MFragmentPagerAdapter(getSupportFragmentManager(), mListFragment, mDetailFragment);
In addition, the data from the list / details is taken from the classic Skakespeare example, so I doubt that my Samsung S4 is out of memory.