1

我在片段中有一个viewpager,我可以很好地滚动页面。当我将新片段添加到后堆栈时,新片段会按预期显示在旧片段容器中。一旦我按下旧片段,就会显示旧片段,但是视图寻呼机不再工作,而是焦点切换到滑动菜单(我提交的片段布局是 feinsteins 菜单中的中央布局),当我滑动滑动菜单时打开而不是移动到 viewpager 中的下一页。为什么会这样?

这是我的 Viewpager 适配器,它是片段 atm 中的子类

    static class SamplePagerAdapter extends PagerAdapter {

            private static int[] sDrawables = { R.drawable.main1, R.drawable.main3,
                    R.drawable.main2, R.drawable.main3, R.drawable.main4,
                    R.drawable.main5 };

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

            @Override
            public View instantiateItem(ViewGroup container, int position) {
                ImageView imageView = new ImageView(container.getContext());
                imageView.setImageResource(sDrawables[position]);
                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
//thiscalls back to the Fragmentctivity and switches to the new fragment, problems arise when I go back to this fragment and the viewpager wont swipe to next page
                        ((LeftAndRightActivity) cx).switchFragmentTo(12);

                    }
                });

                // Now just add ImageView to ViewPager and return it
                container.addView(imageView, LayoutParams.MATCH_PARENT,
                        LayoutParams.MATCH_PARENT);

                return imageView;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView((View) object);
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }
        }

这是我的片段的 onCreateView(),其中包含 viewpager(我实际上使用的是 ChrisBanes 的 PullToRefresh Viewpager)

public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null)
            return null;

        if (v != null)
            return v;

        v = inflater.inflate(R.layout.savescreenlayout, container, false);

        mPullToRefreshViewPager = (PullToRefreshBase) v
                .findViewById(R.id.pull_refresh_viewpager);
        mPullToRefreshViewPager.setOnRefreshListener(this);
        mPullToRefreshViewPager.setMode(Mode.PULL_FROM_END);

        vp = (ViewPager) mPullToRefreshViewPager.getRefreshableView();

        vp.setAdapter(new SamplePagerAdapter());

        return v;
    }

第一次我的带有 viewpager 的 Fragment 提交很好,就在我从任何其他 Fragment 返回时,viewpager 停止分页,而是打开了滑动菜单。提前感谢您的帮助

4

0 回答 0