viewpager不显示子viewpager

时间:2013-12-27 07:29:52

标签: android android-fragments android-viewpager

在我的课程中,我正在调用另一个类来在对话框中显示片段

   public class FragmentT extends Fragment implements AnimationListener {
    ImageButton btn;
    Context cxt;

    RelativeLayout fragmentT;


        View vPOp;
        Animation animation;
         ViewPager pager;



    @Override
    public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub

        if (container == null) {

            return null;
        }
        cxt=getActivity();
        this.activity=getActivity();
        vPOp = inflater.inflate(R.layout.pop, container, false);
        pager = (ViewPager) vPOp.findViewById(R.id.up);

        btn = (ImageButton) vPop.findViewById(R.id.button);



        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub



                new DialogFragmentWindow().show(getSupportFragmentManager(),"");

            }
        });



        return vPop;
    }






    @Override
    public void onAnimationEnd(Animation arg0) {
        // TODO Auto-generated method stub

    }



    @Override
    public void onAnimationRepeat(Animation arg0) {
        // TODO Auto-generated method stub

    }



    @Override
    public void onAnimationStart(Animation arg0) {
        // TODO Auto-generated method stub

    }

}

其中DialogFragmentWindow是

public class DialogFragmentWindow extends DialogFragment {
    PageAdapter pPageAdapter;
    Context context;
    ViewPager vp;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.pop, container);
        context = getActivity();
    //  this.activity=getActivity();
         vp = (ViewPager) view.findViewById(R.id.pVF);

        List<Fragment> fragments = getFragments();
            FragmentAdapter pA = new FragmentAdapter(getChildFragmentManager(),fragments);

            vp.setAdapter(pA);

            getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);


        return view;
    }


    private List getFragments() {
        List<Fragment> fragmentPop = new Vector<Fragment>();
        //fragmentPop.add(FragSc1.newInstance());
        fragmentPop.add(Fragment.instantiate(context,
                FragSc1.class.getName()));
        fragmentPop.add(Fragment.instantiate(context,
                FragSc2.class.getName()));

        return fragmentPop;
    }



}

所以问题是,DialogFragmentWindow既不接受参数getChildFragmentManager(),也不接受FragmentT类,

new DialogFragmentWindow().show(getSupportFragmentManager(), "");

我正在调用的viewpager在另一个布局中,所以想要使用getChildFragmentManager(),不能理解thwe prob,第一次使用chid片段/ viewpager。

1 个答案:

答案 0 :(得分:2)

试着像这样做。它可能对你有帮助。

new DialogFragmentWindow().show(getSupportFragmentManager().beginTransaction(), "dialog");