2

我的代码:

 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”始终为空。任何人都可以提供一个例子吗?tkx!

4

1 回答 1

1

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

片段中的片段

于 2012-12-17T03:40:29.837 回答