android – volley在通过导航抽屉将先前的片段替换为新片段时显示新片段中的先前片段响应

前端之家收集整理的这篇文章主要介绍了android – volley在通过导航抽屉将先前的片段替换为新片段时显示新片段中的先前片段响应前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在导航图中总共有12个片段..每个片段都有一个凌空方法.
每个片段显示自己的凌空响应,除了position = 1和position = 5片段.

我的应用程序启动时

情形1:i打开位置1片段,在打开位置5片段后,两个片段都具有位置1片段响应.

场景2:如果我打开位置5片段并且在打开位置1片段之后比两个片段都具有位置1片段响应.

场景1图像:


场景2图像:


我的片段事务方法类:

private void showFragment(Fragment fragment) {
    llContainer = (LinearLayout)findViewById(R.id.container);
    if (fragment != null) {
        llContainer.removeAllViewsInLayout();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.container,fragment,fragment.getClass().getName());
        fragmentTransaction.commit();
        fragmentManager.popBackStack();
    }
}


@Override
public void onItemSelected(int position) {
    Fragment frag = null;
    switch (position) {
        case POS_HOME:
            frag = FragmentHome.instance(screenTitles[position]);
            break;
        case POS_INBox:
            txtToolbarTitle.setVisibility(View.VISIBLE);
            txtToolbarTitle.setText("Notifications");
            frag = FragmentInBox.instance(screenTitles[position]);
            break;
        case POS_LOG:
            frag = FragmentLog.instance(screenTitles[position]);;
            break;
        case POS_BOOK:
            frag = FragmentBook.instance(screenTitles[position]);
            break;
        case POS_BUILDING:
            frag = FragmentBuilding.instance(screenTitles[position]);
            break;
        case POS_LAWS:
            frag = FragmentLaws.instance();
            break;
        case POS_DOCUMENT:
            frag = FragmentDocument.instance(screenTitles[position]);
            break;
        case POS_EVENT:
            frag = FragmentEvent.instance(screenTitles[position]);
            break;
        case POS_BOARD:
            frag = FragmentBoard.instance(screenTitles[position]);
            break;
        case POS_AROUND:
            frag = FragmentAround.instance(screenTitles[position]);
            break;
        case POS_PROFILE:
            frag = FragmentProfile.instance(screenTitles[position]);
            break;
        case POS_CONCIERGE:
            frag = FragmentConcierge.instance(screenTitles[position]);
            break;
    }

    showFragment(frag);
    mSlideMenu.closeMenu();
}

解决方法

问题出在viewPagers中,在两个片段中viewpager都有相同的id.所以我只是改变了fragmentInBox的viewpager id,现在它正在工作.
原文链接:https://www.f2er.com/android/317713.html

猜你在找的Android相关文章