case R.id.section:
int orientation = getResources().getConfiguration().orientation;
FrameLayout FragmentContainer = (FrameLayout) findViewById(R.id.FragmentContainer);
switch (orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
if (FragmentContainer.getVisibility() == View.VISIBLE) {
getSupportFragmentManager().beginTransaction().remove(new FragmentOne()).commit();
} else {
getSupportFragmentManager().beginTransaction().add(R.id.FragmentContainer, new FragmentOne()).commit();
}
break;
case Configuration.ORIENTATION_PORTRAIT:
if (FragmentContainer.getVisibility() == View.VISIBLE) {
getSupportFragmentManager().beginTransaction().remove(new FragmentTwo()).commit();
} else {
getSupportFragmentManager().beginTransaction().add(R.id.FragmentContainer, new FragmentTwo()).commit();
}
break;
}
フレームレイアウトの可視性に基づいてフラグメントを削除/追加しようとしていますが、メニュー項目をクリックしても何も起こりません...
以下は、XML で定義されたフレーム レイアウトです。
<FrameLayout
android:id="@+id/FragmentContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
add and replace
フラグメントの両方の方法を試しました。