Search in sources :

Example 36 with FragmentTransaction

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");
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View) Fragment(android.support.v4.app.Fragment)

Example 37 with FragmentTransaction

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");
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) DialogFragment(android.support.v4.app.DialogFragment) Fragment(android.support.v4.app.Fragment) DialogFragment(android.support.v4.app.DialogFragment)

Example 38 with FragmentTransaction

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();
        }
    });
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View)

Example 39 with FragmentTransaction

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();
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 40 with FragmentTransaction

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();
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction)

Aggregations

FragmentTransaction (android.support.v4.app.FragmentTransaction)392 Fragment (android.support.v4.app.Fragment)135 FragmentManager (android.support.v4.app.FragmentManager)79 View (android.view.View)29 DialogFragment (android.support.v4.app.DialogFragment)27 FragmentActivity (android.support.v4.app.FragmentActivity)25 Bundle (android.os.Bundle)21 TextView (android.widget.TextView)19 FragmentTransaction (android.app.FragmentTransaction)18 Intent (android.content.Intent)18 Button (android.widget.Button)17 OnClickListener (android.view.View.OnClickListener)16 SherlockFragment (com.actionbarsherlock.app.SherlockFragment)12 ActionBar (android.support.v7.app.ActionBar)8 TargetApi (android.annotation.TargetApi)6 AppCompatActivity (android.support.v7.app.AppCompatActivity)6 Toolbar (android.support.v7.widget.Toolbar)6 FriendsTimeLineFragment (org.qii.weiciyuan.ui.maintimeline.FriendsTimeLineFragment)6 UserInfoFragment (org.qii.weiciyuan.ui.userinfo.UserInfoFragment)6 Transition (android.transition.Transition)5