Merge "update show/hide button"

This commit is contained in:
Todd Kennedy
2015-09-21 18:01:28 +00:00
committed by Android (Google) Code Review
2 changed files with 16 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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) {