如何使用fragmentAdapter在不同情况下接收不同的片段

时间:2017-03-17 10:14:25

标签: android android-fragments android-viewpager android-adapter

我有一个活动,我试图实现一个viewpager。 问题在于每种情况都可能有不同数量的碎片和屏幕显示出来。

基本上在我当前的项目中,对象可以包含4个数据项,每个数据项对应一个不同的片段。

例如,如果我有数据项1,3和4而2缺少滑动需要从1到3然后4和向后滑动需要去4,3,1

所以我写了getCount方法,以确保我有多少,我使用一个地图来完成列表,并确保它们正确映射。 然而,应用程序本身会出错并显示不同于所需的碎片。 我想知道我错过了什么,是否有更好的方法?

public DemoFragmentAdapter(FragmentManager fm, MYObject currentObject) {
        super(fm);
        set_currentObject(currentObject);
        createItemConvertionMap();
    }

@Override
    public int getCount() {
        int count=0;
        if (_currentObject.get_type1()!=null&&_currentObject.get_type1().isEmpty()==false)
        {
            count++;
        }
        if (_currentObject.get_type2()!=null&&
                _currentObject.get_type2().isEmpty()==false)
        {
            count++;
        }
        if (_currentObject.get_type3()!=null&&
                _currentObject.get_type3().isEmpty()==false)
        {
            count++;
        }
        if (_currentObject.get_type4()!=null&&_currentObject.get_type4().isEmpty()==false)
        {
            count++;
        }
        Log.d(MyApplication.LOG_TAG,"fragment adaprter - count:\n"+count);

        return count;
    }

public void createItemConvertionMap() {
        _convertionMap=new HashMap<>();
        int i=0;
        if (_currentObject.get_type1()!=null&&_currentObject.get_type1().isEmpty()==false)
        {
            _convertionMap.put(i, TYPE1);
            i++;
        }
        if (_currentObject.get_type2()!=null&&
                _currentObject.get_type2().isEmpty()==false)
        {
            _convertionMap.put(i, TYPE2);
            i++;
        }
        if (_currentObject.get_type3()!=null&&
                _currentObject.get_type3().isEmpty()==false)
        {
            _convertionMap.put(i, TYPE3);
            i++;
        }
        if (_currentObject.get_type4()!=null&&_currentObject.get_type4().isEmpty()==false)
        {
            _convertionMap.put(i, TYPE4);
            i++;
        }
    }

@Override
    public Fragment getItem(int i) {
        Fragment fragment=new FragmentType1();//default
        Bundle args = new Bundle();
        int fragmentItem=get_convertionMap().get(i);
        Log.d(MyApplication.LOG_TAG,"fragment adaprter - item key requested:"+i +" item convertion is:"+fragmentItem);
        switch (fragmentItem) {
        case TYPE1:
            Log.d(MyApplication.LOG_TAG,"fragment adaprter - returning TYPE1 fragment");
            fragment=new FragmenType1();
            break;
        case TYPE2:
            Log.d(MyApplication.LOG_TAG,"fragment adaprter - returning TYPE2fragment");
            fragment=new FragmentType2();
            break;
        case TYPE3:
            Log.d(MyApplication.LOG_TAG,"fragment adaprter - returning TYPE3 fragment");
            fragment=new FragmentType3();
            break;

        case TYPE4:
            Log.d(MyApplication.LOG_TAG,"fragment adaprter - returning TYPE 4 fragment");
            fragment=new FragmentType4();   
            break;
        default:
            Log.d(MyApplication.LOG_TAG,"fragment adaprter - an error with returend converted item returning default fragment");
            break;
        }
        // TODO finish object bundle
        args.putInt(MyActivity.ARG_OBJECT, i + 1);
        fragment.setArguments(args);
        return fragment;
    }

激活后的日志第一个对象显示它有2个数据项并且正确的第二个不正常工作它有3个数据项但是当pagar通过它们时它变为TYPE1,TYPE4,TYPE4而不是TYPE1,TYPE2, TYPE4:

03-17 15:05:16.482: D/GABI(955): fragment adaprter - count:
03-17 15:05:16.482: D/GABI(955): 2
03-17 15:05:16.492: D/GABI(955): fragment adaprter - count:
03-17 15:05:16.492: D/GABI(955): 2
03-17 15:05:16.494: D/GABI(955): fragment adaprter - item key requested:0 item convertion is:0
03-17 15:05:16.494: D/GABI(955): fragment adaprter - returning TYPE1 fragment
03-17 15:05:16.494: D/GABI(955): fragment adaprter - item key requested:1 item convertion is:3
03-17 15:05:16.494: D/GABI(955): fragment adaprter - returning TYPE4 fragment
03-17 15:05:16.494: D/GABI(955): fragment adaprter - count:
03-17 15:05:16.494: D/GABI(955): 2
03-17 15:05:16.550: D/GABI(955): fragment adaprter - count:
03-17 15:05:16.550: D/GABI(955): 2
03-17 15:05:16.588: D/GABI(955): fragment adaprter - count:
03-17 15:05:16.588: D/GABI(955): 2
03-17 15:05:16.588: D/GABI(955): fragment adaprter - count:
03-17 15:05:16.588: D/GABI(955): 2
03-17 15:05:16.589: D/GABI(955): fragment adaprter - count:
03-17 15:05:16.589: D/GABI(955): 2
03-17 15:05:43.133: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.133: D/GABI(955): 2
03-17 15:05:43.134: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.134: D/GABI(955): 2
03-17 15:05:43.134: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.134: D/GABI(955): 2
03-17 15:05:43.160: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.160: D/GABI(955): 2
03-17 15:05:43.177: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.177: D/GABI(955): 2
03-17 15:05:43.194: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.194: D/GABI(955): 2
03-17 15:05:43.195: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.195: D/GABI(955): 2
03-17 15:05:43.197: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.197: D/GABI(955): 2
03-17 15:05:43.210: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.210: D/GABI(955): 2
03-17 15:05:43.210: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.210: D/GABI(955): 2
03-17 15:05:43.212: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.212: D/GABI(955): 2
03-17 15:05:43.245: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.245: D/GABI(955): 2
03-17 15:05:43.245: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.245: D/GABI(955): 2
03-17 15:05:43.246: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.246: D/GABI(955): 2
03-17 15:05:43.273: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.273: D/GABI(955): 2
03-17 15:05:43.273: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.273: D/GABI(955): 2
03-17 15:05:43.273: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.273: D/GABI(955): 2
03-17 15:05:43.274: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.274: D/GABI(955): 2
03-17 15:05:43.274: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.274: D/GABI(955): 2
03-17 15:05:43.279: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.279: D/GABI(955): 2
03-17 15:05:43.294: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.294: D/GABI(955): 2
03-17 15:05:43.311: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.311: D/GABI(955): 2
03-17 15:05:43.326: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.326: D/GABI(955): 2
03-17 15:05:43.343: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.343: D/GABI(955): 2
03-17 15:05:43.360: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.360: D/GABI(955): 2
03-17 15:05:43.376: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.376: D/GABI(955): 2
03-17 15:05:43.393: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.393: D/GABI(955): 2
03-17 15:05:43.410: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.410: D/GABI(955): 2
03-17 15:05:43.426: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.426: D/GABI(955): 2
03-17 15:05:43.443: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.443: D/GABI(955): 2
03-17 15:05:43.459: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.459: D/GABI(955): 2
03-17 15:05:43.476: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.476: D/GABI(955): 2
03-17 15:05:43.493: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.493: D/GABI(955): 2
03-17 15:05:43.509: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.509: D/GABI(955): 2
03-17 15:05:43.527: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.527: D/GABI(955): 2
03-17 15:05:43.543: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.543: D/GABI(955): 2
03-17 15:05:43.560: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.560: D/GABI(955): 2
03-17 15:05:43.577: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.577: D/GABI(955): 2
03-17 15:05:43.593: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.593: D/GABI(955): 2
03-17 15:05:43.610: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.610: D/GABI(955): 2
03-17 15:05:43.627: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.627: D/GABI(955): 2
03-17 15:05:43.643: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.643: D/GABI(955): 2
03-17 15:05:43.660: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.660: D/GABI(955): 2
03-17 15:05:43.677: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.677: D/GABI(955): 2
03-17 15:05:43.694: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.694: D/GABI(955): 2
03-17 15:05:43.710: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.710: D/GABI(955): 2
03-17 15:05:43.727: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.727: D/GABI(955): 2
03-17 15:05:43.744: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.744: D/GABI(955): 2
03-17 15:05:43.760: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.760: D/GABI(955): 2
03-17 15:05:43.777: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.777: D/GABI(955): 2
03-17 15:05:43.794: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.794: D/GABI(955): 2
03-17 15:05:43.810: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.810: D/GABI(955): 2
03-17 15:05:43.828: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.828: D/GABI(955): 2
03-17 15:05:43.845: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.845: D/GABI(955): 2
03-17 15:05:43.860: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.860: D/GABI(955): 2
03-17 15:05:43.861: D/GABI(955): fragment adaprter - count:
03-17 15:05:43.861: D/GABI(955): 2
03-17 15:05:45.112: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.112: D/GABI(955): 2
03-17 15:05:45.112: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.112: D/GABI(955): 2
03-17 15:05:45.112: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.112: D/GABI(955): 2
03-17 15:05:45.147: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.147: D/GABI(955): 2
03-17 15:05:45.164: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.164: D/GABI(955): 2
03-17 15:05:45.180: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.180: D/GABI(955): 2
03-17 15:05:45.180: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.180: D/GABI(955): 2
03-17 15:05:45.182: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.182: D/GABI(955): 2
03-17 15:05:45.198: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.198: D/GABI(955): 2
03-17 15:05:45.199: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.199: D/GABI(955): 2
03-17 15:05:45.200: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.200: D/GABI(955): 2
03-17 15:05:45.214: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.214: D/GABI(955): 2
03-17 15:05:45.214: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.214: D/GABI(955): 2
03-17 15:05:45.216: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.216: D/GABI(955): 2
03-17 15:05:45.243: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.243: D/GABI(955): 2
03-17 15:05:45.243: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.243: D/GABI(955): 2
03-17 15:05:45.244: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.244: D/GABI(955): 2
03-17 15:05:45.251: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.251: D/GABI(955): 2
03-17 15:05:45.251: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.251: D/GABI(955): 2
03-17 15:05:45.252: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.252: D/GABI(955): 2
03-17 15:05:45.264: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.264: D/GABI(955): 2
03-17 15:05:45.264: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.264: D/GABI(955): 2
03-17 15:05:45.265: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.265: D/GABI(955): 2
03-17 15:05:45.280: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.280: D/GABI(955): 2
03-17 15:05:45.281: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.281: D/GABI(955): 2
03-17 15:05:45.281: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.281: D/GABI(955): 2
03-17 15:05:45.297: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.297: D/GABI(955): 2
03-17 15:05:45.298: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.298: D/GABI(955): 2
03-17 15:05:45.298: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.298: D/GABI(955): 2
03-17 15:05:45.314: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.314: D/GABI(955): 2
03-17 15:05:45.314: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.314: D/GABI(955): 2
03-17 15:05:45.316: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.316: D/GABI(955): 2
03-17 15:05:45.331: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.331: D/GABI(955): 2
03-17 15:05:45.331: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.331: D/GABI(955): 2
03-17 15:05:45.332: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.332: D/GABI(955): 2
03-17 15:05:45.348: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.348: D/GABI(955): 2
03-17 15:05:45.349: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.349: D/GABI(955): 2
03-17 15:05:45.350: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.350: D/GABI(955): 2
03-17 15:05:45.366: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.366: D/GABI(955): 2
03-17 15:05:45.366: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.366: D/GABI(955): 2
03-17 15:05:45.366: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.366: D/GABI(955): 2
03-17 15:05:45.366: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.366: D/GABI(955): 2
03-17 15:05:45.366: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.366: D/GABI(955): 2
03-17 15:05:45.366: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.366: D/GABI(955): 2
03-17 15:05:45.366: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.366: D/GABI(955): 2
03-17 15:05:45.367: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.367: D/GABI(955): 2
03-17 15:05:45.382: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.382: D/GABI(955): 2
03-17 15:05:45.399: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.399: D/GABI(955): 2
03-17 15:05:45.416: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.416: D/GABI(955): 2
03-17 15:05:45.432: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.432: D/GABI(955): 2
03-17 15:05:45.448: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.448: D/GABI(955): 2
03-17 15:05:45.465: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.465: D/GABI(955): 2
03-17 15:05:45.482: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.482: D/GABI(955): 2
03-17 15:05:45.498: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.498: D/GABI(955): 2
03-17 15:05:45.515: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.515: D/GABI(955): 2
03-17 15:05:45.532: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.532: D/GABI(955): 2
03-17 15:05:45.549: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.549: D/GABI(955): 2
03-17 15:05:45.566: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.566: D/GABI(955): 2
03-17 15:05:45.582: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.582: D/GABI(955): 2
03-17 15:05:45.599: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.599: D/GABI(955): 2
03-17 15:05:45.616: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.616: D/GABI(955): 2
03-17 15:05:45.632: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.632: D/GABI(955): 2
03-17 15:05:45.649: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.649: D/GABI(955): 2
03-17 15:05:45.666: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.666: D/GABI(955): 2
03-17 15:05:45.682: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.682: D/GABI(955): 2
03-17 15:05:45.699: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.699: D/GABI(955): 2
03-17 15:05:45.716: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.716: D/GABI(955): 2
03-17 15:05:45.732: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.732: D/GABI(955): 2
03-17 15:05:45.749: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.749: D/GABI(955): 2
03-17 15:05:45.766: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.766: D/GABI(955): 2
03-17 15:05:45.783: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.783: D/GABI(955): 2
03-17 15:05:45.799: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.799: D/GABI(955): 2
03-17 15:05:45.816: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.816: D/GABI(955): 2
03-17 15:05:45.833: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.833: D/GABI(955): 2
03-17 15:05:45.850: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.850: D/GABI(955): 2
03-17 15:05:45.867: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.867: D/GABI(955): 2
03-17 15:05:45.883: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.883: D/GABI(955): 2
03-17 15:05:45.899: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.899: D/GABI(955): 2
03-17 15:05:45.916: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.916: D/GABI(955): 2
03-17 15:05:45.933: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.933: D/GABI(955): 2
03-17 15:05:45.949: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.949: D/GABI(955): 2
03-17 15:05:45.966: D/GABI(955): fragment adaprter - count:
03-17 15:05:45.966: D/GABI(955): 2
03-17 15:05:51.150: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.150: D/GABI(955): 2
03-17 15:05:51.150: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.150: D/GABI(955): 2
03-17 15:05:51.150: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.150: D/GABI(955): 2
03-17 15:05:51.150: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.150: D/GABI(955): 2
03-17 15:05:51.165: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.165: D/GABI(955): 3
03-17 15:05:51.170: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.170: D/GABI(955): 3
03-17 15:05:51.170: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.170: D/GABI(955): 3
03-17 15:05:51.186: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.186: D/GABI(955): 3
03-17 15:05:51.186: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.186: D/GABI(955): 3
03-17 15:05:51.258: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.258: D/GABI(955): 3
03-17 15:05:51.272: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.272: D/GABI(955): 3
03-17 15:05:51.272: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.272: D/GABI(955): 3
03-17 15:05:51.273: D/GABI(955): fragment adaprter - count:
03-17 15:05:51.273: D/GABI(955): 3
03-17 15:05:52.996: D/GABI(955): fragment adaprter - count:
03-17 15:05:52.996: D/GABI(955): 3
03-17 15:05:52.996: D/GABI(955): fragment adaprter - count:
03-17 15:05:52.996: D/GABI(955): 3
03-17 15:05:52.996: D/GABI(955): fragment adaprter - count:
03-17 15:05:52.996: D/GABI(955): 3
03-17 15:05:53.017: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.017: D/GABI(955): 3
03-17 15:05:53.034: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.034: D/GABI(955): 3
03-17 15:05:53.051: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.051: D/GABI(955): 3
03-17 15:05:53.051: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.051: D/GABI(955): 3
03-17 15:05:53.053: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.053: D/GABI(955): 3
03-17 15:05:53.067: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.067: D/GABI(955): 3
03-17 15:05:53.067: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.067: D/GABI(955): 3
03-17 15:05:53.069: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.069: D/GABI(955): 3
03-17 15:05:53.084: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.084: D/GABI(955): 3
03-17 15:05:53.084: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.084: D/GABI(955): 3
03-17 15:05:53.086: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.086: D/GABI(955): 3
03-17 15:05:53.100: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.100: D/GABI(955): 3
03-17 15:05:53.100: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.100: D/GABI(955): 3
03-17 15:05:53.101: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.101: D/GABI(955): 3
03-17 15:05:53.106: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.106: D/GABI(955): 3
03-17 15:05:53.106: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.106: D/GABI(955): 3
03-17 15:05:53.106: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.106: D/GABI(955): 3
03-17 15:05:53.117: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.117: D/GABI(955): 3
03-17 15:05:53.134: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.134: D/GABI(955): 3
03-17 15:05:53.151: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.151: D/GABI(955): 3
03-17 15:05:53.168: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.168: D/GABI(955): 3
03-17 15:05:53.184: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.184: D/GABI(955): 3
03-17 15:05:53.201: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.201: D/GABI(955): 3
03-17 15:05:53.218: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.218: D/GABI(955): 3
03-17 15:05:53.234: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.234: D/GABI(955): 3
03-17 15:05:53.251: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.251: D/GABI(955): 3
03-17 15:05:53.268: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.268: D/GABI(955): 3
03-17 15:05:53.284: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.284: D/GABI(955): 3
03-17 15:05:53.301: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.301: D/GABI(955): 3
03-17 15:05:53.318: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.318: D/GABI(955): 3
03-17 15:05:53.335: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.335: D/GABI(955): 3
03-17 15:05:53.351: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.351: D/GABI(955): 3
03-17 15:05:53.368: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.368: D/GABI(955): 3
03-17 15:05:53.385: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.385: D/GABI(955): 3
03-17 15:05:53.401: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.401: D/GABI(955): 3
03-17 15:05:53.418: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.418: D/GABI(955): 3
03-17 15:05:53.435: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.435: D/GABI(955): 3
03-17 15:05:53.452: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.452: D/GABI(955): 3
03-17 15:05:53.468: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.468: D/GABI(955): 3
03-17 15:05:53.485: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.485: D/GABI(955): 3
03-17 15:05:53.485: D/GABI(955): fragment adaprter - item key requested:2 item convertion is:3
03-17 15:05:53.485: D/GABI(955): fragment adaprter - returning TYPE4 fragment
03-17 15:05:53.485: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.485: D/GABI(955): 3
03-17 15:05:53.490: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.490: D/GABI(955): 3
03-17 15:05:53.490: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.490: D/GABI(955): 3
03-17 15:05:53.491: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.491: D/GABI(955): 3
03-17 15:05:53.976: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.976: D/GABI(955): 3
03-17 15:05:53.976: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.976: D/GABI(955): 3
03-17 15:05:53.976: D/GABI(955): fragment adaprter - count:
03-17 15:05:53.976: D/GABI(955): 3
03-17 15:05:54.003: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.003: D/GABI(955): 3
03-17 15:05:54.019: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.019: D/GABI(955): 3
03-17 15:05:54.020: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.020: D/GABI(955): 3
03-17 15:05:54.022: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.022: D/GABI(955): 3
03-17 15:05:54.036: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.036: D/GABI(955): 3
03-17 15:05:54.036: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.036: D/GABI(955): 3
03-17 15:05:54.038: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.038: D/GABI(955): 3
03-17 15:05:54.053: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.053: D/GABI(955): 3
03-17 15:05:54.053: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.053: D/GABI(955): 3
03-17 15:05:54.054: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.054: D/GABI(955): 3
03-17 15:05:54.069: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.069: D/GABI(955): 3
03-17 15:05:54.069: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.069: D/GABI(955): 3
03-17 15:05:54.070: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.070: D/GABI(955): 3
03-17 15:05:54.075: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.075: D/GABI(955): 3
03-17 15:05:54.075: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.075: D/GABI(955): 3
03-17 15:05:54.075: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.075: D/GABI(955): 3
03-17 15:05:54.086: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.086: D/GABI(955): 3
03-17 15:05:54.103: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.103: D/GABI(955): 3
03-17 15:05:54.120: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.120: D/GABI(955): 3
03-17 15:05:54.136: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.136: D/GABI(955): 3
03-17 15:05:54.153: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.153: D/GABI(955): 3
03-17 15:05:54.170: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.170: D/GABI(955): 3
03-17 15:05:54.187: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.187: D/GABI(955): 3
03-17 15:05:54.203: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.203: D/GABI(955): 3
03-17 15:05:54.220: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.220: D/GABI(955): 3
03-17 15:05:54.237: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.237: D/GABI(955): 3
03-17 15:05:54.254: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.254: D/GABI(955): 3
03-17 15:05:54.270: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.270: D/GABI(955): 3
03-17 15:05:54.287: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.287: D/GABI(955): 3
03-17 15:05:54.303: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.303: D/GABI(955): 3
03-17 15:05:54.321: D/GABI(955): fragment adaprter - count:
03-17 15:05:54.321: D/GABI(955): 3

1 个答案:

答案 0 :(得分:1)

我想我知道你的问题是什么。正如我所说,viewpagers offscreenpage默认值和最小值是1.所以第一个片段是类型1.第二个片段是类型4.现在你的对象将被更新,类型2被添加。但是片段1(类型1)和2(类型4)已经加载并且在你的viewpagers缓存中。

更新前的地图:

索引0 =类型1

索引1 =类型4

更新后的地图:

索引0 =类型1

索引1 =类型2&lt; - 这一个是新的

索引2 =类型4

您目前在屏幕上看到的内容:

索引0 =类型1

索引1 =类型4&lt; - 这一个未更新(应该是2)

索引2 =类型4

但新类型(类型2)不会被更新,因为它已经加载并缓存在索引1处。适配器将正确创建索引2的片段,类型4。