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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s