Fragment堆栈的问题

时间:2012-10-01 14:36:16

标签: android fragment

我的平板电脑有2个窗格。左边一个是列表,右边一个将根据选择显示每个列表项的详细信息。在我的右侧窗格中,我为每个选定的列表项显示了一系列片段。问题是当我点击序列中的第二个片段时,它必须显示第三个片段,然而它首先显示几秒钟,然后它将显示第三个片段。 这一切都在第二次PANE中 就像在第二个窗格中的1个项目一样 点击1片段 - >显示2片段 - >点击2片段 - >显示1(几秒钟) - >显示3片段 - >

但它应该是这样的 点击1 - >显示2 - >点击2 - >显示3 - >

我需要做一些使Fragment堆栈设置正确的事情

请检查以下代码

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    if (selected_item != null)
        if (selected_item != v) {
            if (selct_item_bg_color != 0)
                selected_item.setBackgroundColor(Color
                        .alpha(selct_item_bg_color));
            else {
                int rgb = Utill.hex2decimal("D2");
                //int rgb3=Utill.hex2decimal("82");
                selected_item.setBackgroundColor(Color.rgb(rgb, rgb, rgb));
                //selected_item.setBackgroundColor(Color.GRAY);
                Log.e("", "DEFAULT NOT SELECTED");
            }
        }
    selected_item = v;
    selct_item_bg_color = v.getDrawingCacheBackgroundColor();


    selected_item.setBackgroundDrawable(v.getContext().getResources()
            .getDrawable(R.drawable.list_selector));
    Log.e("POSITION", "SELECTED ITEM POSITION : " + position);

    FragmentManager frMgr = this.getFragmentManager();
    FragmentTransaction xaction = frMgr.beginTransaction();
    switch (position) {
    case 0:
        ScheduleFragment sc_fragment = new ScheduleFragment();
        xaction.add(R.id.second_pane, sc_fragment, "itinerary");
        xaction.commit();
        break;
    case 1:
        ItineraryFragment it_fragment = new ItineraryFragment();
        xaction.add(R.id.second_pane, it_fragment, "itinerary");
        xaction.commit();
        break;
    case 2:
        VenueFragment vn_fragment = new VenueFragment();
        xaction.add(R.id.second_pane, vn_fragment, "Venue");
        xaction.commit();
        break;
    case 3:
        Bundle sendData=new Bundle();
        sendData.putString("URL", URL+utilclass.getMyDbHelper().getToken());
        sendData.putString("TITLE", "Search");
       //intent.putExtra("URL", URL+utilclass.getMyDbHelper().getToken());
        //intent.putExtra("TITLE", "Search");

        SearchWebFragment sw_fragment = new SearchWebFragment();
        sw_fragment.setArguments(sendData);
        xaction.add(R.id.second_pane, sw_fragment, "searchWeb");
        xaction.commit();
        break;

    default: Log.e("","Please Choose Right option");

    }

1 个答案:

答案 0 :(得分:0)

    I make it done by setting transaction to close using the below statement

    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);


   used as: 

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    Fragment frag=new AbstractAuthorsFragment();
    transaction.replace(R.id.second_pane, frag);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
    transaction.addToBackStack(null);
    transaction.commit();