每當我跑我的應用程序,並單擊列表項,預期的碎片也出現,但名單片段不從視野中消失(參見附截圖)。需要做什麼才能從用戶的視圖中刪除列表?名單片段沒有消失
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();
後退按鈕方法
@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();
}
}
發佈您的代碼,所以要修正錯誤。 – Sajidkhan