Example usage for android.support.v4.app FragmentTransaction commit

List of usage examples for android.support.v4.app FragmentTransaction commit

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction commit.

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:com.actionbarsherlock.sample.demos.app.FragmentHideShowSupport.java

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);/*from  w ww.j  a  va 2 s . c o m*/
                button.setText("Hide");
            } else {
                ft.hide(fragment);
                button.setText("Show");
            }
            ft.commit();
        }
    });
}

From source file:com.baise.law.widgets.FragmentTabHost.java

public void addTab(TabSpec tabSpec, Class<?> clss, Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mContext));
    String tag = tabSpec.getTag();

    TabInfo info = new TabInfo(tag, clss, args);

    if (mAttached) {
        // If we are already attached to the window, then check to make
        // sure this tab's fragment is inactive if it exists. This shouldn't
        // normally happen.
        info.fragment = mFragmentManager.findFragmentByTag(tag);
        if (info.fragment != null && !info.fragment.isDetached()) {
            FragmentTransaction ft = mFragmentManager.beginTransaction();
            //              ft.detach(info.fragment);
            ft.hide(info.fragment);/*from   ww  w  .  j ava 2s .  com*/
            ft.commit();
        }
    }

    mTabs.add(info);
    addTab(tabSpec);
}

From source file:cl.ipp.katbag.fragment.Worlds.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) super.getActivity();
    v = inflater.inflate(R.layout.fragment_worlds, container, false);
    mainActivity.supportInvalidateOptionsMenu();

    // rescues parameters
    Bundle bundle = getArguments();/*from  w  ww. j  av  a 2s  . c  om*/
    if (bundle != null) {
        id_app = bundle.getLong("id_app");
    }

    notRegister = (TextView) v.findViewById(R.id.world_not_register);
    editMode = false;
    loadListView();

    worldsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!editMode) {
                TextView idWorld = (TextView) view.findViewById(R.id.world_row_id);

                Bundle bundle = new Bundle();
                bundle.putLong("id_world", Long.valueOf(idWorld.getText().toString()));
                bundle.putString("name_world", idWorld.getText().toString());

                mFragment = new OneWorld();
                mFragment.setArguments(bundle);
                FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
                t.replace(R.id.fragment_main_container, mFragment);
                t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                t.addToBackStack(mFragment.getClass().getSimpleName());
                t.commit();
            }
        }
    });

    return v;
}

From source file:cl.ipp.katbag.fragment.Drawings.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) super.getActivity();
    v = inflater.inflate(R.layout.fragment_drawings, container, false);
    mainActivity.supportInvalidateOptionsMenu();

    // rescues parameters
    Bundle bundle = getArguments();//  ww  w  .  j a v a  2 s.  c  om
    if (bundle != null) {
        id_app = bundle.getLong("id_app");
        type_app = bundle.getString("type_app");
    }

    notRegister = (TextView) v.findViewById(R.id.drawings_not_register);
    editMode = false;
    loadListView();

    drawingsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!editMode) {
                TextView idDrawing = (TextView) view.findViewById(R.id.drawing_row_id);

                Bundle bundle = new Bundle();
                bundle.putLong("id_drawing", Long.valueOf(idDrawing.getText().toString()));
                bundle.putString("name_drawing", idDrawing.getText().toString());
                bundle.putString("type_app", type_app);

                mFragment = new OneDrawing();
                mFragment.setArguments(bundle);
                FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
                t.replace(R.id.fragment_main_container, mFragment);
                t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                t.addToBackStack(mFragment.getClass().getSimpleName());
                t.commit();
            }
        }
    });

    return v;
}

From source file:cl.ipp.katbag.fragment.Edit.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.fragment_edit, container, false);
    mainActivity = (MainActivity) super.getActivity();

    notRegister = (TextView) v.findViewById(R.id.edit_not_register);
    editMode = false;//from w w w .j a  va2  s  .c o m
    loadListView();

    editListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!editMode) {
                TextView idApp = (TextView) view.findViewById(R.id.edit_row_id);
                TextView nameApp = (TextView) view.findViewById(R.id.edit_row_name);
                TextView typeApp = (TextView) view.findViewById(R.id.edit_row_type_app);

                // initialize parameters of add class
                Add.id_app = Long.valueOf(idApp.getText().toString());
                Add.name_app_text = nameApp.getText().toString();

                Bundle bundle = new Bundle();
                bundle.putString("type_app", typeApp.getText().toString());

                mFragment = new Add();
                mFragment.setArguments(bundle);
                FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
                t.replace(R.id.fragment_main_container, mFragment);
                t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                t.addToBackStack(mFragment.getClass().getSimpleName());
                t.commit();
            }
        }
    });

    // id exposes
    editListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            TextView idApp = (TextView) arg1.findViewById(R.id.edit_row_id);
            KatbagUtilities.message(mainActivity.context,
                    getString(R.string.edit_get_id) + " " + idApp.getText().toString());
            return false;
        }
    });

    return v;
}

From source file:com.audiokernel.euphonyrmt.library.SimpleLibraryActivity.java

@Override
public void pushLibraryFragment(final Fragment fragment, final String label) {
    final String title;
    if (fragment instanceof BrowseFragment) {
        title = ((BrowseFragment) fragment).getTitle();
    } else {/* ww w.  j  a  v a2s . c o  m*/
        title = fragment.toString();
    }
    setTitle(title);
    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.replace(R.id.root_frame, fragment);
    ft.addToBackStack(label);
    ft.setBreadCrumbTitle(title);
    ft.commit();
}

From source file:com.byteshaft.licenseservice.StartTestActivity.java

public void loadFragment(Fragment fragment) {
    FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
    tx.replace(R.id.container, fragment);
    tx.commit();
}

From source file:com.actionbarsherlock.sample.fragments.FragmentMenuSupport.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(SampleList.THEME); //Used for theme switching in samples
    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");
    }//from w  ww  . jav  a 2 s. c om
    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();
}

From source file:com.akop.bach.activity.RibbonedSinglePane.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(getLayout());//from   w  ww  .  j a  va 2  s  .  c  om

    if (mAccount == null)
        mAccount = (BasicAccount) getIntent().getParcelableExtra("account");

    if (mAccount == null) {
        if (App.getConfig().logToConsole())
            App.logv("Account is null");

        finish();
        return;
    }

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        new ActionBarHelper().init();
    }

    FragmentManager fm = getSupportFragmentManager();
    Fragment titleFrag;

    FragmentTransaction ft = fm.beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    if ((titleFrag = fm.findFragmentByTag("details")) == null) {
        titleFrag = createFragment();
        ft.replace(R.id.fragment_titles, titleFrag, "details");
    }

    ft.commit();
}

From source file:com.bslee.logtoolapk.widget.FragmentTabHost.java

public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mContext));
    String tag = tabSpec.getTag();

    TabInfo info = new TabInfo(tag, clss, args);

    if (mAttached) {
        // If we are already attached to the window, then check to make
        // sure this tab's fragment is inactive if it exists. This shouldn't
        // normally happen.
        info.fragment = mFragmentManager.findFragmentByTag(tag);
        if (info.fragment != null && !info.fragment.isDetached()) {
            FragmentTransaction ft = mFragmentManager.beginTransaction();
            //            ft.detach(info.fragment);
            ft.hide(info.fragment);//from   w  w  w . j av a2  s.  c om
            ft.commit();
        }
    }

    mTabs.add(info);
    addTab(tabSpec);
}