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

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

概述我正在使用片段寻呼机适配器实例化我的片段类.我能够这样做但我的问题是我的getItem()方法调用两次,这进一步产生了问题.你解释我为什么会发生这种情况. package com.creatiosoft.rssfeed.adaptor; import android.content.Context; import android.support.v4.app.Fragment; 我正在使用片段寻呼机适配器实例化我的片段类.我能够这样做但我的问题是我的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;        }    }@H_301_3@  

我用这段代码调用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);@H_301_3@解决方法 请注意,寻呼机至少保持一页.这意味着当创建寻呼机时,他创建至少两个页面 – 他显示的页面和下一个页面,以便允许“分页”.                  总结       

以上是内存溢出为你收集整理的使用Fragment Pager Adapter时,android-getItem()方法被调用两次全部内容,希望文章能够帮你解决使用Fragment Pager Adapter时,android-getItem()方法被调用两次所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1134840.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存