是否可以将ViewPager添加到DialogFragment中?

时间:2012-12-17 03:17:20

标签: android android-viewpager

我的代码:

 public class CustomDialogFragment extends SherlockDialogFragment {
            /** The system calls this to get the DialogFragment's layout, regardless
                of whether it's being displayed as a dialog or an embedded fragment. */
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
                View v = inflater.inflate(R.layout.p_product_gallery, container, false);
                ImageView tttiv=(ImageView)v.findViewById(R.id.test_image);
                tttiv.setImageResource(R.drawable.baozi);
                return v;
            }

            /** The system calls this only when creating the layout in a dialog. */
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                // The only reason you might override this method when using onCreateView() is
                // to modify any dialog characteristics. For example, the dialog includes a
                // title by default, but your custom layout might not need it. So here you can
                // remove the dialog title, but you must call the superclass to get the Dialog.
                mDialog = super.onCreateDialog(savedInstanceState);
                mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                mDialog.getWindow().setBackgroundDrawable((new ColorDrawable(0x0f000000)));
                mPager = (ViewPager) mDialog.findViewById(R.id.aa_pager);
                mPager.setAdapter(mAdapter);            

                mAdapter = new ProductGalleryAdapter(getSupportFragmentManager());


                return mDialog;
            }
        }

“mPager”始终为null。 任何人都可以提供一个例子吗? TKX!

1 个答案:

答案 0 :(得分:1)

除非您使用的是Android 4.2(和Android支持库版本11),否则片段不支持片段...

Fragments within Fragments