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

时间:2017-10-16 06:32:44

标签: android android-fragments android-volley fragmenttransaction

我在导航图中总共有12个片段..每个片段都有一个凌空方法。 每个片段显示自己的截击响应,除了position = 1和position = 5片段。

我的应用开始时

情景1:我打开位置1片段,在我打开位置5片段后,两个片段都有位置1片段响应。

场景2:如果我打开位置5片段并且打开位置1片段后,两个片段都有位置1片段响应。

场景1图片:

FragmentInbox FragmentLaws

场景2图片:

FragmentLaws FragmentInbox

我的片段事务方法类:

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();
}

1 个答案:

答案 0 :(得分:0)

问题出在viewPagers中,在两个片段中,viewpager都有相同的id。所以我只是改变了fragmentInbox的viewpager id,现在正在工作。