public void onClick(View v) { updateFragmentVisibility(); } };
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_menu); // Make sure the two menu fragments are created. FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mFragment1 = fm.findFragmentByTag("f1"); if (mFragment1 == null) { mFragment1 = new MenuFragment(); ft.add(mFragment1, "f1"); } mFragment2 = fm.findFragmentByTag("f2"); if (mFragment2 == null) { mFragment2 = new Menu2Fragment(); ft.add(mFragment2, "f2"); } ft.commit(); // Watch check box clicks. mCheckBox1 = (CheckBox)findViewById(R.id.menu1); mCheckBox1.setOnClickListener(mClickListener); mCheckBox2 = (CheckBox)findViewById(R.id.menu2); mCheckBox2.setOnClickListener(mClickListener); // Make sure fragments start out with correct visibility. updateFragmentVisibility(); }
void updateFragmentVisibility() { FragmentTransaction ft = getFragmentManager().beginTransaction(); if (mCheckBox1.isChecked()) ft.show(mFragment1); else ft.hide(mFragment1); if (mCheckBox2.isChecked()) ft.show(mFragment2); else ft.hide(mFragment2); ft.commit(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_menu); // Make sure the two menu fragments are created. FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mFragment1 = fm.findFragmentByTag("f1"); if (mFragment1 == null) { mFragment1 = new MenuFragment(); ft.add(mFragment1, "f1"); } mFragment2 = fm.findFragmentByTag("f2"); if (mFragment2 == null) { mFragment2 = new Menu2Fragment(); ft.add(mFragment2, "f2"); } ft.commit(); // Watch check box clicks. mCheckBox1 = (CheckBox)findViewById(R.id.menu1); mCheckBox1.setOnClickListener(mClickListener); mCheckBox2 = (CheckBox)findViewById(R.id.menu2); mCheckBox2.setOnClickListener(mClickListener); // Make sure fragments start out with correct visibility. updateFragmentVisibility(); }
void updateFragmentVisibility() { FragmentTransaction ft = getFragmentManager().beginTransaction(); if (mCheckBox1.isChecked()) ft.show(mFragment1); else ft.hide(mFragment1); if (mCheckBox2.isChecked()) ft.show(mFragment2); else ft.hide(mFragment2); ft.commit(); }
public void onClick(View v) { updateFragmentVisibility(); } };
@Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); // Make sure fragments are updated after check box view state is restored. updateFragmentVisibility(); }
@Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); // Make sure fragments are updated after check box view state is restored. updateFragmentVisibility(); }