From 5383dc24fc63e40a309dbe62c81716d58dcbb29c Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Thu, 23 Jul 2015 10:06:18 -0700 Subject: [PATCH] update show/hide button A Fragment saves its hidden state. Update the text of the button accodring to state of the Fragment. Bug: 22666353 --- .../com/example/android/apis/app/FragmentHideShow.java | 10 ++++++++-- .../android/supportv4/app/FragmentHideShowSupport.java | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/samples/ApiDemos/src/com/example/android/apis/app/FragmentHideShow.java b/samples/ApiDemos/src/com/example/android/apis/app/FragmentHideShow.java index e5e259968..3e9619de4 100644 --- a/samples/ApiDemos/src/com/example/android/apis/app/FragmentHideShow.java +++ b/samples/ApiDemos/src/com/example/android/apis/app/FragmentHideShow.java @@ -43,8 +43,14 @@ public class FragmentHideShow extends Activity { // The content view embeds two fragments; now retrieve them and attach // their "hide" button. FragmentManager fm = getFragmentManager(); - addShowHideListener(R.id.frag1hide, fm.findFragmentById(R.id.fragment1)); - addShowHideListener(R.id.frag2hide, fm.findFragmentById(R.id.fragment2)); + Fragment fragment1 = fm.findFragmentById(R.id.fragment1); + addShowHideListener(R.id.frag1hide, fragment1); + final Button button1 = (Button)findViewById(R.id.frag1hide); + button1.setText(fragment1.isHidden() ? "Show" : "Hide"); + Fragment fragment2 = fm.findFragmentById(R.id.fragment2); + addShowHideListener(R.id.frag2hide, fragment2); + final Button button2 = (Button)findViewById(R.id.frag2hide); + button2.setText(fragment2.isHidden() ? "Show" : "Hide"); } void addShowHideListener(int buttonId, final Fragment fragment) { diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentHideShowSupport.java b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentHideShowSupport.java index e0fcbdb82..34415062c 100644 --- a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentHideShowSupport.java +++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentHideShowSupport.java @@ -44,8 +44,14 @@ public class FragmentHideShowSupport extends FragmentActivity { // The content view embeds two fragments; now retrieve them and attach // their "hide" button. FragmentManager fm = getSupportFragmentManager(); - addShowHideListener(R.id.frag1hide, fm.findFragmentById(R.id.fragment1)); - addShowHideListener(R.id.frag2hide, fm.findFragmentById(R.id.fragment2)); + Fragment fragment1 = fm.findFragmentById(R.id.fragment1); + addShowHideListener(R.id.frag1hide, fragment1); + final Button button1 = (Button)findViewById(R.id.frag1hide); + button1.setText(fragment1.isHidden() ? "Show" : "Hide"); + Fragment fragment2 = fm.findFragmentById(R.id.fragment2); + addShowHideListener(R.id.frag2hide, fragment2); + final Button button2 = (Button)findViewById(R.id.frag2hide); + button2.setText(fragment2.isHidden() ? "Show" : "Hide"); } void addShowHideListener(int buttonId, final Fragment fragment) {