Getchildfragmentmanager nested snippets causing a crash

I have a viewPager that contains fragments, each of these fragments has a viewpager for displaying images and banners

now for each fragment the Image Adapter I pass getChildFragmentManager () as shown below

CarouselAdapter carouselAdapter = new CarouselAdapter(getChildFragmentManager());

But the above code crashes when changing tabs on the view tab showing the following message

java.lang.IllegalArgumentException: No view found for id 0x7f1000ef 

But if I pass getFragmentManager (), this does not crash, but for some time the adapter becomes empty. The idea of ​​how to handle nested fragments.

I use FragmentPagerAdapter for both viewers, but still not working

Below is the crashlog

 java.lang.IllegalArgumentException: No view found for id 0x7f1000ef (com.packagename:id/viewPagerBanners) for fragment MainBannerFragmentNew{308cb84 #0 id=0x7f1000ef android:switcher:2131755247:0}
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1292)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1523)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1585)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2832)
                                                                         at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2199)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1323)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
                                                                         at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
                                                                         at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1969)
                                                                         at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:620)
                                                                         at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
                                                                         at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                         at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                         at android.support.v4.view.ViewPager$3.run(ViewPager.java:273)
                                                                         at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                         at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                                         at android.view.Choreographer.doFrame(Choreographer.java:603)
                                                                         at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                                         at android.os.Handler.handleCallback(Handler.java:746)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

Below is the carousel adapter code

public class CarouselAdapter extends FragmentPagerAdapter {

private List<CarouselItem> carouselItemsList;

public CarouselAdapter(FragmentManager fm, List<CarouselItem> carouselItemsList) {
    super(fm);
    this.carouselItemsList = carouselItemsList;

}

@Override
public Fragment getItem(int position) {
    return MainBannerFragmentNew.newInstance(R.drawable.gray_logo, carouselItemsList.get(position));
}

@Override
public int getCount() {
    return carouselItemsList.size();
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    super.destroyItem(container, position, object);
}
}

Below is the rolling code of the tab adapter

public class HomeTabsPagerAdapter extends FragmentPagerAdapter {
ArrayList<HomeTabItem> homeTabItems;

public HomeTabsPagerAdapter(FragmentManager manager, ArrayList<HomeTabItem> homeTabItems) {
    super(manager);
    this.homeTabItems = homeTabItems;
}

@Override
public Fragment getItem(int position) {
    HomeTabItem homeTabItem = homeTabItems.get(position);
    return OfferZoneFragment.newInstance(homeTabItem.getId());

}

@Override
public int getCount() {
    return homeTabItems.size();
}

@Override
public CharSequence getPageTitle(int position) {
    return homeTabItems.get(position).getTitle();
}
}

recyclerview, recylerview viewpager, bindview

((BannerHolder) holder).viewPager.setAdapter(new CarouselAdapter(fragmentManager, homePageItems.get(position).carouselItems));
                ((BannerHolder) holder).circlePageIndicator.setViewPager(((BannerHolder) holder).viewPager);
                final float density = context.getResources().getDisplayMetrics().density;
                ((BannerHolder) holder).circlePageIndicator.setBackgroundColor(0x00000000);
                ((BannerHolder) holder).circlePageIndicator.setRadius(5 * density);
                ((BannerHolder) holder).circlePageIndicator.setFillColor(ContextCompat.getColor(context, R.color.appthemecolor));
                ((BannerHolder) holder).circlePageIndicator.setPageColor(0xFFFFFFFF);
                ((BannerHolder) holder).circlePageIndicator.setStrokeColor(0x00000000);
                ((BannerHolder) holder).circlePageIndicator.setStrokeWidth(2 * density);
                if (((BannerHolder) holder).viewPager.getAdapter().getCount() <= 1) {
                    ((BannerHolder) holder).circlePageIndicator.setVisibility(View.GONE);
                } else {
                    ((BannerHolder) holder).circlePageIndicator.setVisibility(View.VISIBLE);
                }
+6
2

getChildFragmentManager .

:

, viewpager (child), viewpager ( ).

:

ViewPager onAttachedToWindow .

. IllegalArgumentException: id - ViewPager ViewPager.

Update:

getFragmentManager getSupportFragmentManager, PagerAdapter android.support.v4.app.FragmentPagerAdapter android.support.v4.app.FragmentStatePagerAdapter.

+6

FragmentPagerAdapter FragmentStatePagerAdapter , .

0

Source: https://habr.com/ru/post/1014320/


All Articles