それが役立つ場合、私が欲しいのは、このGoogleチュートリアルで行われていることと似ています
ただし、遷移の前にフラグメントが作成されます。これを行うと、移行は正常に機能します。しかし、私はこのアプローチを使用できません
=====
API 7+を目指して、画面全体に1つのフラグメントを表示し、ボタン(onTouchイベントを使用して描画されたボタン)を使用してから、2番目のフラグメントに切り替え、その逆を試みています。
しかし、最初のフラグメントを 2 番目のフラグメントに置き換えるか、fragmentTransaction.show と fragmentTransaction.hide を使用すると、空白の画面が表示されます。空白の画面になる前に2回切り替えることができます。バックスタックに入れたくありません。
MainActivity の onCreate でフラグメントを作成しています。
DiceTable diceTable = new DiceTable();
Logger logger = new Logger();
fragmentTransaction.add(diceTable, DICETABLE_TAG);
fragmentTransaction.add(logger, LOGGER_TAG);
fragmentTransaction.add(R.id.fragment_container, logger);
fragmentTransaction.add(R.id.fragment_container, diceTable);
次に、1 つのメソッド (フラグメントから呼び出される) で切り替えを行います。
Logger logger = (Logger)fragmentManager.findFragmentByTag(LOGGER_TAG);
DiceTable diceTable = (DiceTable)fragmentManager.findFragmentByTag(DICETABLE_TAG);
if (diceTable.isVisible()) {
fragmentTransaction.replace(R.id.fragment_container, logger);
fragmentTransaction.commit();
fragmentTransaction.hide(diceTable);
fragmentTransaction.show(logger);
}
else if (logger.isVisible()) {
fragmentTransaction.replace(R.id.fragment_container, diceTable);
fragmentTransaction.commit();
fragmentTransaction.hide(logger);
fragmentTransaction.show(diceTable);
}
これは私がこれを行うべき方法ではありませんか?
フラグメント置換時のブランク画面