2012-10-01 52 views
0

我在我的平板電腦中有2個窗格。左邊是List,右邊會顯示基於選擇的每個列表項的詳細信息。在我的右窗格中,我爲每個選定的列表項目顯示了片段序列。問題是當我點擊序列中的第二個片段時,它必須顯示第三個片段,然而它首先顯示幾秒鐘,然後顯示第三個片段。 全部在第二個PANE中 它就像在第二個窗格中的1個項目 點擊1片段→顯示2片段→點擊2片段→顯示1(幾秒鐘)→顯示3片段→問題與片段堆棧

,但它應該是這樣 單擊1 - >顯示2 - >點擊2 - >顯示3 - >

我需要做的一些東西,使碎片堆設置正確

請檢查代碼如下

@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"); 

    } 

回答

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