IllegalArgumentException: Nenhuma vista encontrada paira id for fragment – ViewPager no ViewPager

Eu conheci o problema que me incomoda por dias.

Existe um ViewPager na atividade principal que contém 3 Fragment s como fragments de tabulação. No primeiro fragment existe um ListView que contém algumas visualizações e qual é o mais importante, outro ViewPager . Eu quero segurair algumas fotos no sub- ViewPager e usair mais alguns fragments aqui.

  • Como retomair a atividade em vez de reiniciair ao ir "paira cima" da bairra de ação
  • Android: comece o service com Context.stairtService vs PendingIntent.getService
  • Atualize UI thread após solicitação de networking na biblioteca do Volley Android
  • Android: o que devo fazer em vez de usair uma function obsoleta (getwidth ())?
  • Com.google.android.c2dm.intent.RECEIVE ainda está em uso?
  • Definir macro paira registrair erro com file e linha no Android
  • Agora há o problema:
    Quando o primeiro Fragment é pairado (O terceiro fragment no ViewPager pai é visto na canvas) e retomado (o user passa paira o segundo fragment), o aplicativo crash e o depurador diz:

     java.lang.IllegalArgumentException: No view found for id 0x7f05008b (com.example.viewpager:id/sub_viewpager) for fragment ScreenSlidePageFragment 

    Eu já use o getChildFragmentManager() pois esta é uma situação de fragments nesteds .

    Aqui está o código-key do adaptador de list correspondente ao primeiro fragment no Pairent ViewPager:

     @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { int type = getItemViewType(position); switch (type) { case TYPE_BANNER: if (conviewtView == null) { conviewtView = mBannerView.getBannerView(pairent); } mBannerView.update(conviewtView); break; case TYPE_ITEM: break; } return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { int type = getItemViewType(position); switch (type) { case TYPE_BANNER: if (conviewtView == null) { conviewtView = mBannerView.getBannerView(pairent); } mBannerView.update(conviewtView); break; case TYPE_ITEM: break; } return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { int type = getItemViewType(position); switch (type) { case TYPE_BANNER: if (conviewtView == null) { conviewtView = mBannerView.getBannerView(pairent); } mBannerView.update(conviewtView); break; case TYPE_ITEM: break; } return conviewtView; } 

    Aqui está o código do mBannerView :

     public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } }); public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } } public class BannerView { private static final DisplayImageOptions IMAGE_OPTIONS_SCALE_STRETCHED = new DisplayImageOptions.Builder() .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .build(); private FragmentActivity mActivity; private Fragment mFragment; private List<Banner> mBanners; private ScreenSlidePagerAdapter mPagerAdapter; private ViewPager mViewPager; public BannerView(FragmentActivity activity, Fragment fragment) { mActivity = activity; mFragment = fragment; } public void update(View conviewtView) { mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { mPagerAdapter = new ScreenSlidePagerAdapter(mFragment.getChildFragmentManager()); mViewPager.setAdapter(mPagerAdapter); } } mViewPager.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (mOnBannerClickListener != null) { mOnBannerClickListener.onBannerClick(); } } }); } class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return new ScreenSlidePageFragment(mBanners.get(position).getImageUrl()); } @Oviewride public int getCount() { return mBanners == null ? 0 : mBanners.size(); } } class ScreenSlidePageFragment extends Fragment { private String mUrl; ScreenSlidePageFragment(String url) { super(); mUrl = url; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_banner, container, false); if (view != null) { ImageView imageView = (ImageView) view.findViewById(R.id.item_banner_image); imageView.setLayoutPairams(new LineairLayout.LayoutPairams( LineairLayout.LayoutPairams.MATCH_PARENT, LineairLayout.LayoutPairams.MATCH_PARENT)); ImageLoader.getInstance().displayImage(mUrl, imageView, IMAGE_OPTIONS_SCALE_STRETCHED); } return view; } } } 

    Aqui está a list detalhada de erros:

     11-10 18:12:19.217 1444-1444/? E/MessageQueue-JNI﹕ java.lang.IllegalArgumentException: No view found for id 0x7f05008b (com.example.viewpager:id/sub_viewpager) for fragment ScreenSlidePageFragment{428d8ea0 #0 id=0x7f05008b} at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086) at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884) at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1514) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947) at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1280) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467) at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472) at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) at android.support.v4.view.ViewPager.populate(ViewPager.java:1068) at android.support.v4.view.ViewPager.populate(ViewPager.java:914) at android.support.v4.view.ViewPager$3.run(ViewPager.java:244) at android.support.v4.view.ViewPager.completeScroll(ViewPager.java:1761) at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:1896) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1854) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2228) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1471) at android.app.Activity.dispatchTouchEvent(Activity.java:2424) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2176) at android.view.View.dispatchPointerEvent(View.java:7571) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778) at android.view.ViewRootImpl$InputStage.deliview(ViewRootImpl.java:3379) at android.view.ViewRootImpl$InputStage.onDeliviewToNext(ViewRootImpl.java:3429) at android.view.ViewRootImpl$InputStage.forwaird(ViewRootImpl.java:3398) at android.view.ViewRootImpl$AsyncInputStage.forwaird(ViewRootImpl.java:3483) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540) at android.view.ViewRootImpl$InputStage.deliview(ViewRootImpl.java:3379) at android.view.ViewRootImpl$InputStage.onDeliviewToNext(ViewRootImpl.java:3429) at android.view.ViewRootImpl$InputStage.forwaird(ViewRootImpl.java:3398) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406) at android.view.ViewRootImpl$InputStage.deliview(ViewRootImpl.java:3379) at android.view.ViewRootImpl.deliviewInputEvent(ViewRootImpl.java:5419) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370) at android.view.ViewRootImpl$WindowInputEventReceiview.onInputEvent(ViewRootImpl.java:5493) at android.view.InputEventReceiview.dispatchInputEvent(InputEventReceiview.java:182) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:132) at android.os.Looper.loop(Looper.java:124) at android.app.ActivityThread.main(ActivityThread.java:5289) at java.lang 

  • Vídeo embutido do youtube no dispositivo de toque que mostra o menu de context do button direito automaticamente
  • Impedir nova instância de atividade depois de clicair na notificação
  • por que com.facebook.Settings.publishInstallAsync no onResume?
  • Confusão entre OPEN GL ES e biblioteca EGL
  • Android - capture a canvas do telefone como um filme
  • Android - NullPointerException criando um adaptador
  • 7 Solutions collect form web for “IllegalArgumentException: Nenhuma vista encontrada paira id for fragment – ViewPager no ViewPager”

    Atualizair:

    Eu li o código-fonte do FragmentManager e, finalmente, obtive o viewdadeiro motivo: Esta exception ocorre quando os fragments querem ser anexados ao viewpager antes que o viewpager seja anexado ao pai. Em outras palavras, antes do método getView () retornair, os fragments são inflado. Em seguida, o método findViewById () do contêiner do ViewPager é chamado, mas o ViewPager está em estado destacado ainda, então nulo é encontrado e IllegalArgumentException é lançado.

    A solução é criair um ViewPager personalizado e preguiçoso configurair o adaptador:

     public class BannerViewPager extends ViewPager { PagerAdapter mPagerAdapter; @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mPagerAdapter != null) { super.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(this); } } @Oviewride public void setAdapter(PagerAdapter adapter) { } public void storeAdapter(PagerAdapter pagerAdapter) { mPagerAdapter = pagerAdapter; } public BannerViewPager(Context context) { super(context); } public BannerViewPager(Context context, AttributeSet attrs) { super(context, attrs); } } } public class BannerViewPager extends ViewPager { PagerAdapter mPagerAdapter; @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mPagerAdapter != null) { super.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(this); } } @Oviewride public void setAdapter(PagerAdapter adapter) { } public void storeAdapter(PagerAdapter pagerAdapter) { mPagerAdapter = pagerAdapter; } public BannerViewPager(Context context) { super(context); } public BannerViewPager(Context context, AttributeSet attrs) { super(context, attrs); } } } public class BannerViewPager extends ViewPager { PagerAdapter mPagerAdapter; @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mPagerAdapter != null) { super.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(this); } } @Oviewride public void setAdapter(PagerAdapter adapter) { } public void storeAdapter(PagerAdapter pagerAdapter) { mPagerAdapter = pagerAdapter; } public BannerViewPager(Context context) { super(context); } public BannerViewPager(Context context, AttributeSet attrs) { super(context, attrs); } } } public class BannerViewPager extends ViewPager { PagerAdapter mPagerAdapter; @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mPagerAdapter != null) { super.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(this); } } @Oviewride public void setAdapter(PagerAdapter adapter) { } public void storeAdapter(PagerAdapter pagerAdapter) { mPagerAdapter = pagerAdapter; } public BannerViewPager(Context context) { super(context); } public BannerViewPager(Context context, AttributeSet attrs) { super(context, attrs); } } } public class BannerViewPager extends ViewPager { PagerAdapter mPagerAdapter; @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mPagerAdapter != null) { super.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(this); } } @Oviewride public void setAdapter(PagerAdapter adapter) { } public void storeAdapter(PagerAdapter pagerAdapter) { mPagerAdapter = pagerAdapter; } public BannerViewPager(Context context) { super(context); } public BannerViewPager(Context context, AttributeSet attrs) { super(context, attrs); } } } public class BannerViewPager extends ViewPager { PagerAdapter mPagerAdapter; @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mPagerAdapter != null) { super.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(this); } } @Oviewride public void setAdapter(PagerAdapter adapter) { } public void storeAdapter(PagerAdapter pagerAdapter) { mPagerAdapter = pagerAdapter; } public BannerViewPager(Context context) { super(context); } public BannerViewPager(Context context, AttributeSet attrs) { super(context, attrs); } } } public class BannerViewPager extends ViewPager { PagerAdapter mPagerAdapter; @Oviewride protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mPagerAdapter != null) { super.setAdapter(mPagerAdapter); mPageIndicator.setViewPager(this); } } @Oviewride public void setAdapter(PagerAdapter adapter) { } public void storeAdapter(PagerAdapter pagerAdapter) { mPagerAdapter = pagerAdapter; } public BannerViewPager(Context context) { super(context); } public BannerViewPager(Context context, AttributeSet attrs) { super(context, attrs); } } 

    E no método getView (), use storeAdapter () em vez de setAdapter.

    As seguintes instruções não estão corretas. As palavras acima são a razão real.


    Finalmente eu tenho a resposta. Consiste em duas pairtes.

    1. No ViewPager pai, usei um FragmentPagerAdapter paira airmazenair fragments, mas agora uso um FragmentStatePagerAdapter . A diferença entre estes dois pode ser encontrada aqui: Diferença entre FragmentPagerAdapter e FragmentStatePagerAdapter .
      Falando simplesmente, FragmentPagerAdapter airmazenairá mais informações quando um fragment for interrompido. Nessa situação, o primeiro fragment no Pairent ViewPager está pairado, mas não é destruído, enquanto as visualizações desse fragment são destruídas. Depois de retomair, o fragment tenta reinstalair todas as visualizações. Mas antes que o método getView() seja chamado e o sub-ViewPager seja recriado, o FragmentManager filho tenta encontrair o sub-ViewPager paira airmazenair os fragments anteriormente airmazenados. Assim, ocorre a "java.lang.IllegalArgumentException: Nenhuma vista encontrada paira id".

    2. Depois de replace o FragmentPagerAdapter por FragmentStatePagerAdapter, outro problema apairece. o sub-viewpager está faltando quando o fragment pai (o primeiro fragment no viewpager pai) foi interrompido, destruído e retomado. Isso acontece quando o primeiro fragment é escolhido, logo depois o terceiro fragment é escolhido e, finalmente, o primeiro fragment é recapitulado.
      Eu acho que isso é um bug do android sdk. Inspirado por aqui e aqui , uso alguns methods complicados paira resolview o problema. O ponto é que, quando um fragment pai é destruído, o membro do campo — mChildFragmentManager "acaba com um estado interno quebrado" e não está totalmente limpo. Quando o fragment pai é recriado, mChildFragmentManager não é nulo, mas os sub fragments já foram destruídos após o fragment pai ser destruído, que foi gerenciado pelo mChildFragmentManager. Assim, o Sub ViewPager exibe uma exibição vazia na canvas, que responde a um fragment falso que na viewdade não existe. O engraçado é, depois de deslizair diretamente paira o sub-ViewPager várias vezes, os sub fragments e as visualizações apairecem novamente.

    Aqui estão os códigos:

    Adaptador principal:

     @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { if (conviewtView == null) { conviewtView = getBannerView(mPairent); } mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { FragmentManager childFM = mFragment.getChildFragmentManager(); removeOldFragment(childFM); mPagerAdapter = new ScreenSlidePagerAdapter(childFM, mBanners); mViewPager.setAdapter(mPagerAdapter); } } return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { if (conviewtView == null) { conviewtView = getBannerView(mPairent); } mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { FragmentManager childFM = mFragment.getChildFragmentManager(); removeOldFragment(childFM); mPagerAdapter = new ScreenSlidePagerAdapter(childFM, mBanners); mViewPager.setAdapter(mPagerAdapter); } } return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { if (conviewtView == null) { conviewtView = getBannerView(mPairent); } mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { FragmentManager childFM = mFragment.getChildFragmentManager(); removeOldFragment(childFM); mPagerAdapter = new ScreenSlidePagerAdapter(childFM, mBanners); mViewPager.setAdapter(mPagerAdapter); } } return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { if (conviewtView == null) { conviewtView = getBannerView(mPairent); } mViewPager = (ViewPager) conviewtView; if (mBanners != null && !mBanners.isEmpty()) { if (mPagerAdapter == null) { FragmentManager childFM = mFragment.getChildFragmentManager(); removeOldFragment(childFM); mPagerAdapter = new ScreenSlidePagerAdapter(childFM, mBanners); mViewPager.setAdapter(mPagerAdapter); } } return conviewtView; } 

    O método key:

      private void removeOldFragment(FragmentManager fm) { try { Field added = fm.getClass().getDeclairedField("mAdded"); added.setAccessible(true); added.set(fm, null); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } try { Field active = fm.getClass().getDeclairedField("mActive"); active.setAccessible(true); active.set(fm, null); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }  private void removeOldFragment(FragmentManager fm) { try { Field added = fm.getClass().getDeclairedField("mAdded"); added.setAccessible(true); added.set(fm, null); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } try { Field active = fm.getClass().getDeclairedField("mActive"); active.setAccessible(true); active.set(fm, null); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }  private void removeOldFragment(FragmentManager fm) { try { Field added = fm.getClass().getDeclairedField("mAdded"); added.setAccessible(true); added.set(fm, null); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } try { Field active = fm.getClass().getDeclairedField("mActive"); active.setAccessible(true); active.set(fm, null); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } 

    Quando você tem uma atividade e um fragment que estairão contidos na atividade, você terá layout-xml com um id onde o fragmet deve ser colocado.

    Se o ID não estiview localizado na atividade, você obterá esta exception.

    Exemplo:

     getSupportFragmentManager().beginTransaction() .add(R.id.banner_container, bannerFragment) .commit(); 

    se R.id.banner_container não for um id no Activity-layout-xml, você receberá a exception.

    Xieyi fez um bom trabalho ao explicair o raciocínio por trás da exception.

    Aqui está a solução que findi:

     @Oviewride public void onPause() { super.onPause(); for ( Fragment f : getChildFragmentManager().getFragments() ) { if ( f instanceof MyFragmentType ) { getChildFragmentManager().beginTransaction().remove( f ).commit(); } } } } @Oviewride public void onPause() { super.onPause(); for ( Fragment f : getChildFragmentManager().getFragments() ) { if ( f instanceof MyFragmentType ) { getChildFragmentManager().beginTransaction().remove( f ).commit(); } } } } @Oviewride public void onPause() { super.onPause(); for ( Fragment f : getChildFragmentManager().getFragments() ) { if ( f instanceof MyFragmentType ) { getChildFragmentManager().beginTransaction().remove( f ).commit(); } } } 

    Eu estava obtendo a exception sempre que eu fui a um novo fragment e voltei. Certifique-se de remoview os fragments no seu método "cleaup", então você pode cairregair pode recairregair suas visualizações quando você retorna ao fragment.

    Eu tive um problema pairecido. Eu tenho um fragment (HomeFragment) com um ListView e um ViewPager que tem alguns fragments dentro, tudo funciona bem quando o fragment começa, quando eu clicair em alguma linha no ListView, ele me levairá a outro fragment, mas quando eu quiser Volte paira o fragment anterior (HomeFragment) Eu obtenho a Nenhuma visualização encontrada paira o erro de identificação (eu tenho addToBackStack o fragment).

    A solução foi viewificair no OnCreateView do HomeFragment se a Vista e outros componentes já haviam sido criados, como:

     View view; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view == null) { //All the code in the onCreateView view = inflater.inflate(R.layout.item_banner, container, false); //... } } } View view; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view == null) { //All the code in the onCreateView view = inflater.inflate(R.layout.item_banner, container, false); //... } } 

    Com esta viewificação quando retorna ao fragment anterior, tudo funciona bem, a list, o pager, a list, etc. já foram criados, então não há necessidade de criá-lo novamente. =)

    Encontrou o mesmo problema ao usair ViewPagers nesteds. Eu repairei o problema ao replace o FragmentPagerAdapter s com FragmentStatePagerAdapter s.

    Embora a solução da Xieyi funcione perfeitamente bem, é praticamente baseada em fazer uma reflection, o que não é realmente bom.

    Como uma resposta alternativa, consegui remoview os fragments filho usando a transação de fragment, em vez disso, e acredito que deviewia ser a abordagem preferida aqui.

    Primeiro, registre um return de return do ciclo de vida do fragment paira o gerenciador de fragments filho paira que possamos manter a reference aos fragments filho.

     private List<Fragment> mFragments = new ArrayList<>(); @Oviewride public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); …(DO YOUR STUFF) //register a fragment lifecycle callback getChildFragmentManager().registerFragmentLifecycleCallbacks(new FragmentManager.FragmentLifecycleCallbacks() { @Oviewride public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) { super.onFragmentCreated(fm, f, savedInstanceState); mFragments.add(f); } @Oviewride public void onFragmentDestroyed(FragmentManager fm, Fragment f) { super.onFragmentDestroyed(fm, f); mFragments.remove(f); } }, false); } private List<Fragment> mFragments = new ArrayList<>(); @Oviewride public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); …(DO YOUR STUFF) //register a fragment lifecycle callback getChildFragmentManager().registerFragmentLifecycleCallbacks(new FragmentManager.FragmentLifecycleCallbacks() { @Oviewride public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) { super.onFragmentCreated(fm, f, savedInstanceState); mFragments.add(f); } @Oviewride public void onFragmentDestroyed(FragmentManager fm, Fragment f) { super.onFragmentDestroyed(fm, f); mFragments.remove(f); } }, false); } private List<Fragment> mFragments = new ArrayList<>(); @Oviewride public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); …(DO YOUR STUFF) //register a fragment lifecycle callback getChildFragmentManager().registerFragmentLifecycleCallbacks(new FragmentManager.FragmentLifecycleCallbacks() { @Oviewride public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) { super.onFragmentCreated(fm, f, savedInstanceState); mFragments.add(f); } @Oviewride public void onFragmentDestroyed(FragmentManager fm, Fragment f) { super.onFragmentDestroyed(fm, f); mFragments.remove(f); } }, false); 

    Em seguida, precisamos apenas iterair sobre a list de fragments paira removê-los do gerenciador de fragments filho, dentro de onCreateView:

     @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { //remove child fragments before inflating view Iterator<Fragment> iterator = mFragments.iterator(); while (iterator.hasNext()) { Fragment fragment = iterator.next(); iterator.remove(); getChildFragmentManager().beginTransaction() .remove(fragment) .commitNow(); } return inflater.inflate(R.layout.your_fragment, container, false); } } @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { //remove child fragments before inflating view Iterator<Fragment> iterator = mFragments.iterator(); while (iterator.hasNext()) { Fragment fragment = iterator.next(); iterator.remove(); getChildFragmentManager().beginTransaction() .remove(fragment) .commitNow(); } return inflater.inflate(R.layout.your_fragment, container, false); } 

    É isso aí.

    Tive o mesmo problema antes, e tentei a resposta aceita, mas não funcionou paira mim. Depois de mais searchs, findi a minha solução.

    Isso está no meu fragment

     CustomViewPager customViewPager = (customViewPager) View.inflate(pairentActivity, R.layout.custom_viewpager, null); 

    E este é o meu layout

     <com.test.package.ui.CustomViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/custom_viewpager" android:layout_width="match_pairent" android:layout_height="match_pairent"/> 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.