ViewPager里面的ViewPager没有响应

时间:2017-04-20 08:38:18

标签: android android-fragments android-viewpager

我在xml中使用Vertical View Pager

<com.fadeltd.trivia.VerticalViewPager
    android:id="@+id/result_main_view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</com.fadeltd.trivia.VerticalViewPager>

然后在我的代码中

viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));

class PagerAdapter extends FragmentStatePagerAdapter {
    Fragment fragments[];

    public PagerAdapter(FragmentManager fragmentManager) {
        super(fragmentManager);
        fragments = new Fragment[]{
                ExperienceFragment.newInstance(),
                RankFragment.newInstance(),
                QuestionFragment.newInstance(),
        };
    }

    @Override
    public Fragment getItem(int position) {
        return fragments[position];
    }

    @Override
    public int getCount() {
        return fragments.length;
    }
}

它工作正常,我可以使用视图寻呼机上下滑动,但我想在我的一个片段(QuestionFragment)中使用左右滑动的标准视图寻呼机

public class QuestionFragment extends Fragment {
    ...
    public void setupQuestions() {
        Fragment[] fragments = new Fragment[questionList.size()];
        for (int i = 0; i < questionList.size(); i++) {
            Question question = questionList.get(i);
            switch (question.getType()) {
                case Question.TYPE_TEXT:
                    fragments[i] = QuizTextFragment.newInstance(question);
                    break;
                case Question.TYPE_IMAGE:
                    fragments[i] = QuizImageFragment.newInstance(question);
                    break;
                case Question.TYPE_ESSAY:
                    fragments[i] = QuizEssayFragment.newInstance(question);
                    break;
            }
        }

        PagerAdapter adapter = new PagerAdapter(getChildFragmentManager(), fragments);
        QuestionViewPager.setAdapter(adapter);
    }

    class PagerAdapter extends FragmentStatePagerAdapter {
        Fragment[] fragments;

        public PagerAdapter(FragmentManager fragmentManager, Fragment[] fragments) {
            super(fragmentManager);
            this.fragments = fragments;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments[position];
        }

        @Override
        public int getCount() {
            return fragments.length;
        }
    }
}

但每当我尝试从ViewPager向下滑动到最后一页时,我的应用程序突然冻结,片刻之后,应用程序没有响应

Not Responding

0 个答案:

没有答案