ViewPager in DialogFragment

1. Before API 14, you cannot have nested fragments. So basically you cannot have viewpager in a dialog fragment before API 14. Otherwise you will get an error of IllegalArgumentException: No view found for id 0x7f07003c for fragment,

2. After API 14, nested fragments it’s allowed. Details are in here. When you setup the FragmentPagerAdpater, you will need to put getChildFragmentManager() instead of getFragmentManager(). This will solve the problem.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.sold_out_dialogfragment, container);
    ViewPager pager = (ViewPager) view.findViewById(R.id.soldout_diaglogfragment_pager);
    pager.setAdapter(new SoldOutAdapter(getChildFragmentManager()));
    return view;
}

3. make sure you put false in the nested fragments.

View view=inflater.inflate(R.layout.product_options_soldout_fragment,container,false);
Advertisements