From 9de98193d9ca44f8b4102707f124a81befbf7070 Mon Sep 17 00:00:00 2001 From: it232115 Date: Tue, 16 Jan 2024 11:11:39 +0900 Subject: [PATCH] =?UTF-8?q?QR=E3=83=AA=E3=83=BC=E3=83=80=E3=81=8B=E3=82=89?= =?UTF-8?q?=E6=88=BB=E3=81=A3=E3=81=9F=E6=99=82=E3=81=AB=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=83=83=E3=82=B7=E3=83=A5=E3=81=99=E3=82=8B=E3=83=90=E3=82=B0?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/QRFragment.java | 18 +++++++++++++++++- .../example/childguard/QrPrintFragment.java | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/QRFragment.java b/app/src/main/java/com/example/childguard/QRFragment.java index f97a174..59e21e7 100644 --- a/app/src/main/java/com/example/childguard/QRFragment.java +++ b/app/src/main/java/com/example/childguard/QRFragment.java @@ -9,6 +9,8 @@ import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.browser.customtabs.CustomTabsIntent; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; import android.util.Log; import android.view.LayoutInflater; @@ -101,8 +103,22 @@ public class QRFragment extends Fragment { Log.d("QRFragment", "onClick: called"); //QRリーダ起動 fragmentLauncher.launch(new ScanOptions()); - + HomeFragment homeFragment=new HomeFragment(); + replaceFragment(homeFragment); return view; } + //画面遷移メソッド + private void replaceFragment(Fragment fragment) { + // フラグメントマネージャーの取得 + FragmentManager manager = getParentFragmentManager(); // アクティビティではgetSupportFragmentManager()? + // フラグメントトランザクションの開始 + FragmentTransaction transaction = manager.beginTransaction(); + // レイアウトをfragmentに置き換え(追加) + transaction.replace(R.id.fragmentContainerView, fragment); + // 置き換えのトランザクションをバックスタックに保存する + transaction.addToBackStack(null); + // フラグメントトランザクションをコミット + transaction.commit(); + } } diff --git a/app/src/main/java/com/example/childguard/QrPrintFragment.java b/app/src/main/java/com/example/childguard/QrPrintFragment.java index bdae229..fb8e755 100644 --- a/app/src/main/java/com/example/childguard/QrPrintFragment.java +++ b/app/src/main/java/com/example/childguard/QrPrintFragment.java @@ -138,6 +138,7 @@ public class QrPrintFragment extends Fragment { replaceFragment(homeFragment); return view; } + //画面遷移メソッド private void replaceFragment(Fragment fragment) { // フラグメントマネージャーの取得 FragmentManager manager = getParentFragmentManager(); // アクティビティではgetSupportFragmentManager()?