EDIT 2
I now managed to get rid of the error with using the trick from here https://code.google.com/p/android/issues/detail?id=42601#c10 so that\'s
First of all, English is not my mother tongue, if I have something wrong in grammar,please tell me. I encountered this problem in my project. At first I did what Marc said, and it worked well. But when I added another ViewPager in a father fragment, the new ViewPager showed as same as the old one no matter what kinda code in this new viewpager. At last I found the reason. We always create Fragment by using FragmentTrasaction.replace(R.layout.fragment,fragment) method. Because of this, we create a new fragment instance when we use this method. Instead of using replace() method, I use FragmentTransaction.hide() and show() method to switch fragment. I solved my problem this way. Here is my code snippets :
@Override
public void onClick(View v) {
FragmentTransaction transaction = fm.beginTransaction();
switch (v.getId()) {
case R.id.tv_schedule_day:
hideFragment(transaction);
if (dayFragment == null) {
dayFragment = new ScheduleDayFragment();
transaction.add(R.id.ll_schedule_content, dayFragment);
} else {
transaction.show(dayFragment);
}
transaction.commit();
break;
case R.id.tv_schedule_week:
hideFragment(transaction);
if (weekFragment == null) {
weekFragment = new ScheduleWeekFragment();
transaction.add(R.id.ll_schedule_content, weekFragment);
} else {
transaction.show(weekFragment);
}
transaction.commit();
break;
case R.id.tv_schedule_month:
hideFragment(transaction);
if (monthFragment == null) {
monthFragment = new ScheduleMonthFragment();
transaction.add(R.id.ll_schedule_content, monthFragment);
} else {
transaction.show(monthFragment);
}
transaction.commit();
break;
private void hideFragment(FragmentTransaction transaction) {
if (dayFragment != null) {
transaction.hide(dayFragment);
}
if (weekFragment != null) {
transaction.hide(weekFragment);
}
if (monthFragment != null) {
transaction.hide(monthFragment);
}
}
I use hide() and show() methods to make switch father fragment, so when I use getChildFragmentManager() in embedded fragment, it wolud not return null. This question was asked in 2013, I think no one would see this answer, but I am still very glad to anwser this question.