0

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

但它应该像 Click on 1 -> Display 2 -> Click on 2 -> Display 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");

    }
4

1 回答 1

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();
于 2012-10-03T09:19:25.073 回答