-1

每當我跑我的應用程序,並單擊列表項,預期的碎片也出現,但名單片段不從視野中消失(參見附截圖)。需要做什麼才能從用戶的視圖中刪除列表?名單片段沒有消失

FragmentItem1 newFragment = new FragmentItem1(); 
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 

    transaction.replace(R.id.master_container, newFragment);       

transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 
    transaction.addToBackStack(null); 
    transaction.commit(); 

enter image description here enter image description here

後退按鈕方法

@Override 
public void onBackPressed() { 
    if (mTwoPane) { 
     FragmentMainList newFragment = new FragmentMainList(); 
     FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 

     // Replace whatever is in the master_container view with the above fragment 
     transaction.replace(R.id.master_container, newFragment); 
     transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 

     // Commit the transaction 
     transaction.commit(); 
    } 
} 

enter image description here

+0

發佈您的代碼,所以要修正錯誤。 – Sajidkhan

回答

1

假設 'master_container' 是一個佈局的靠近你的ListView,你是什麼樣的目前觀察的是正確的行爲河ListView不會自動消失。在您的ListView上調用setVisibility以使其消失。使用參數ListView.GONE這種方法

+0

是的,很好但文字沒有做到屏幕的頂部,所以技術上列表片段仍然存在檢查最新截圖。 – MacaronLover

+0

調用View.INVISIBLE後,文本「This is item 1」沒有上升? –

+0

'ListView.GONE'爲此做了很多工作。但是,當我單擊後退按鈕時,列表視圖不會再出現。我怎樣才能確保它呢? – MacaronLover