use of android.support.v4.app.FragmentTransaction in project android-support-v4-googlemaps by petedoyle.
the class FragmentStackSupport method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_stack);
// Watch for button clicks.
Button button = (Button) findViewById(R.id.new_fragment);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
addFragmentToStack();
}
});
button = (Button) findViewById(R.id.home);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// If there is a back stack, pop it all.
FragmentManager fm = getSupportFragmentManager();
if (fm.getBackStackEntryCount() > 0) {
fm.popBackStack(fm.getBackStackEntryAt(0).getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
}
});
if (savedInstanceState == null) {
// Do first time initialization -- add initial fragment.
Fragment newFragment = CountingFragment.newInstance(mStackLevel);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.simple_fragment, newFragment).commit();
} else {
mStackLevel = savedInstanceState.getInt("level");
}
}
use of android.support.v4.app.FragmentTransaction in project android-support-v4-googlemaps by petedoyle.
the class FragmentDialogSupport method showDialog.
void showDialog() {
mStackLevel++;
// DialogFragment.show() will take care of adding the fragment
// in a transaction. We also want to remove any currently showing
// dialog, so make our own transaction and take care of that here.
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
DialogFragment newFragment = MyDialogFragment.newInstance(mStackLevel);
newFragment.show(ft, "dialog");
}
use of android.support.v4.app.FragmentTransaction in project android-support-v4-googlemaps by petedoyle.
the class FragmentHideShowSupport method addShowHideListener.
void addShowHideListener(int buttonId, final Fragment fragment) {
final Button button = (Button) findViewById(buttonId);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
if (fragment.isHidden()) {
ft.show(fragment);
button.setText("Hide");
} else {
ft.hide(fragment);
button.setText("Show");
}
ft.commit();
}
});
}
use of android.support.v4.app.FragmentTransaction in project android-support-v4-googlemaps by petedoyle.
the class FragmentMenuFragmentSupport method updateFragmentVisibility.
// Update fragment visibility based on current check box state.
void updateFragmentVisibility() {
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
if (mCheckBox1.isChecked())
ft.show(mFragment1);
else
ft.hide(mFragment1);
if (mCheckBox2.isChecked())
ft.show(mFragment2);
else
ft.hide(mFragment2);
ft.commit();
}
use of android.support.v4.app.FragmentTransaction in project android-support-v4-googlemaps by petedoyle.
the class FragmentMenuSupport method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_menu);
// Make sure the two menu fragments are created.
FragmentManager fm = getSupportFragmentManager();
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();
}
Aggregations