使用Fragment Pager Adapter时,android-getItem()方法被调用两次

我正在使用片段寻呼机适配器实例化我的片段类.我能够这样做但我的问题是我的getItem()方法调用两次,这进一步产生了问题.你解释我为什么会发生这种情况.
package com.creatiosoft.RSSFeed.adaptor;

    import android.content.Context;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.util.Log;

    import com.creatiosoft.RSSFeed.utils.RSSItem;
    import com.viewpagerindicator.IconPagerAdapter;

    public class NewsFeedsAdapter extends FragmentPagerAdapter implements
            IconPagerAdapter {

        int[] icon = null;
        String[] content = null;
        String[] URLs = null;
        Context cont;

        public NewsFeedsAdapter(FragmentManager fm,Context context) {
            super(fm);
            Log.i("jk","constructor");
            this.cont = context;
            RSSItem newsFeedAppliaction = (RSSItem) cont;
            /*
             * Retrieving the values of the Icons and contents from the application
             * class in utils package
             */
            icon = newsFeedAppliaction.getICONS();
            content = newsFeedAppliaction.getCONTENT();
            URLs = newsFeedAppliaction.getURL();

        }

        /** instantiate a new fragment class */
        @Override
        public Fragment getItem(int position) {
            Log.i("yt","hello" + position);
            return TestFragment.newInstance(position % content.length,cont);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return content[position % content.length].toupperCase();
        }

        public int getIconResId(int index) {
            return icon[index];
        }

        /** return the no of views on the basis of array items */
        @Override
        public int getCount() {

            Log.i("hi","length" + content.length);
            return content.length;
        }
    }

我用这段代码调用Adapter:

NewsFeedsAdapter adapter = new NewsFeedsAdapter(
                getSupportFragmentManager(),getApplicationContext());
        /**
         * get the id of the view pager declared in the xml resource and set the
         * adaptor on the view pager
         */
        ViewPager pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(adapter);
        //pager.setCurrentItem(0);

        /**
         * Tab page indicator class is used to indicate the tabs and is accessed
         * from the library class
         */
        TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
        indicator.setViewPager(pager);

解决方法

请注意,寻呼机至少保持一页.这意味着当创建寻呼机时,他创建至少两个页面 – 他显示页面和下一个页面,以便允许“分页”.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...