Example usage for android.support.v4.app FragmentManager beginTransaction

List of usage examples for android.support.v4.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:com.bashlord.loginregister.nearbyR.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.nearby_list);

    FragmentManager fm = getSupportFragmentManager();
    PlacePickerFragment fragment = (PlacePickerFragment) fm.findFragmentByTag(FRAGTAG);

    if (fragment == null) {
        FragmentTransaction transaction = fm.beginTransaction();
        fragment = new PlacePickerFragment();
        transaction.add(fragment, FRAGTAG);
        transaction.commit();/*  w  w  w.  j  av  a2  s .  c o  m*/
    }

    // Use fragment as click listener for cards, but must implement correct interface
    if (!(fragment instanceof OnCardClickListener)) {
        throw new ClassCastException("PlacePickerFragment must " + "implement OnCardClickListener interface.");
    }
    OnCardClickListener clickListener = (OnCardClickListener) fm.findFragmentByTag(FRAGTAG);

    mRetentionFragment = (StreamRetentionFragment) fm.findFragmentByTag(RETENTION_TAG);
    if (mRetentionFragment == null) {
        mRetentionFragment = new StreamRetentionFragment();
        fm.beginTransaction().add(mRetentionFragment, RETENTION_TAG).commit();
    } else {
        // If the retention fragment already existed, we need to pull some state.
        // pull state out
        CardStreamState state = mRetentionFragment.getCardStream();

        // dump it in CardStreamFragment.
        mCardStreamFragment = (CardStreamFragment) fm.findFragmentById(R.id.fragment_cardstream);
        mCardStreamFragment.restoreState(state, clickListener);
    }
}

From source file:com.coincollection.ReorderCollections.java

private void closeFragment() {
    FragmentManager fm = getActivity().getSupportFragmentManager();
    fm.beginTransaction().remove(this).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit();
    fm.popBackStack();/*from ww  w  .j  a va2  s . co m*/
}

From source file:biz.easymenu.easymenung.ItemFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    WindowManager.LayoutParams WMLP = this.getDialog().getWindow().getAttributes();
    WMLP.windowAnimations = R.style.PauseDialogAnimation;
    this.getDialog().getWindow().setAttributes(WMLP);

    v = li.inflate(R.layout.itemdialog, container, false);

    np = (NumberPicker) v.findViewById(R.id.itemnumpick);
    ((TextView) v.findViewById(R.id.itemLabel)).setText(item.getLabel());
    ((TextView) v.findViewById(R.id.itemDescription)).setText(item.getDescription());
    try {//from w w  w  .  j a va2 s . co m
        ((ImageView) v.findViewById(R.id.itemImage)).setImageBitmap(BitmapFactory
                .decodeStream(getActivity().openFileInput(Integer.toString(item.getIdImage()) + ".img")));
    } catch (FileNotFoundException e) {
        Log.e(EasymenuNGActivity.TAG, "Error image file not found: " + e.getMessage());
    }

    this.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

    new Thread(new NumberRun()).start();

    btnOk = (Button) v.findViewById(R.id.itembtnOK);
    btnOk.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                if (oldNr > 0 || np.getValue() > 0)
                    rpc.addToOrder(sid, item.getIdMenulists(), np.getValue(), note);
            } catch (Exception e) {
                FragmentManager fm = getActivity().getSupportFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                ErrorFragment f = new ErrorFragment(e.getMessage());
                Fragment prev = fm.findFragmentByTag("errorDialog");
                if (prev != null) {
                    ft.remove(prev);
                    ft.commit();
                }
                f.show(ft, "errorDialog");
            } finally {
                dismiss();
            }
        }
    });

    btnNote = (Button) v.findViewById(R.id.itembtnNote);
    btnNote.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getActivity().getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            NoteDialog f = new NoteDialog(itemFrag, note);
            Fragment prev = fm.findFragmentByTag("noteDialog");
            if (prev != null) {
                ft.remove(prev);
                ft.commit();
            }
            f.show(ft, "noteDialog");
        }

    });

    return v;
}

From source file:biz.easymenu.easymenung.TableListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.menupager, container, false);
    ((TextView) v.findViewById(R.id.menuTitle)).setText(R.string.tableList);
    GridView gridview = (GridView) v.findViewById(R.id.gridview);
    adapter = new ItemAdapter(getActivity());
    gridview.setAdapter(adapter);/*w w w  .  j  a  va  2 s  .co  m*/

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            //Toast.makeText(context, "" + position, Toast.LENGTH_SHORT).show();
            FragmentManager fm = getActivity().getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            DialogFragment f = new LoginFragment(adapter.itemsList.get(position));
            Fragment prev = fm.findFragmentByTag("loginDialog");
            if (prev != null) {
                ft.remove(prev);
                ft.commit();
            }
            f.show(ft, "loginDialog");

            /*DEMO
                    
            Locale pLocale = new Locale("it");
            Resources res = getActivity().getBaseContext().getResources();
            DisplayMetrics dm =  getActivity().getBaseContext().getResources().getDisplayMetrics();
            Configuration conf = res.getConfiguration();
            conf.locale = pLocale;
            res.updateConfiguration(conf, dm);
            getActivity().finish();
            startActivity(getActivity().getIntent());
                    
                    
            END DEMO */
        }
    });

    return v;
}

From source file:com.appmanager.parimal.activity.MainActivity.java

private void displayView(String viewLabel, int position) {

    Fragment fragment = null;//from w  w w  . j  av  a2  s.co  m
    String title = new String();

    fragment = new AppCategoryDetailFragment();
    Bundle arguments = new Bundle();
    arguments.putString(AppCategoryDetailFragment.ARG_ITEM_CONTENT, viewLabel);
    fragment.setArguments(arguments);
    title = viewLabel;

    if (fragment != null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.container_body, fragment);
        fragmentTransaction.commit();

        // set the toolbar title
        getSupportActionBar().setTitle(title);
    }
}

From source file:ch.citux.td.ui.fragments.ChannelFragment.java

private void setFragment(Fragment fragment, boolean backstack) {
    if (fragment != null) {
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        if (fragmentManager != null) {
            FragmentTransaction transaction = fragmentManager.beginTransaction();

            if (backstack) {
                transaction.addToBackStack(null);
            }//w w  w.j  a  va2s  .  c  om

            Fragment currentFragment = fragmentManager.findFragmentById(R.id.container);
            if (currentFragment == null) {
                transaction.add(R.id.container, fragment);
            } else {
                if (!currentFragment.equals(fragment)) {
                    transaction.replace(R.id.container, fragment);
                } else {
                    ((TDBase) fragment).loadData();
                }
            }
            transaction.commit();
        }
    }
}

From source file:com.by_syk.lib.nanoiconpack.ReqStatsActivity.java

private void showFragment() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    ReqStatsFragment reqStatsFragment = (ReqStatsFragment) fragmentManager
            .findFragmentByTag("reqStatsFragment");
    if (reqStatsFragment != null) {
        fragmentManager.beginTransaction().show(reqStatsFragment).commit();
    } else {//  w w  w.  ja va  2s .  c  o  m
        fragmentManager.beginTransaction()
                .add(R.id.fragment_content, ReqStatsFragment.newInstance(), "reqStatsFragment").commit();
    }
    //        getSupportFragmentManager().beginTransaction()
    //                .replace(R.id.fragment_content, ReqStatsFragment.newInstance(), "reqStatsFragment")
    //                .commit();
}

From source file:com.cypress.cysmart.GATTDBFragments.GattDescriptorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_gatt_list, container, false);
    mApplication = (CySmartApplication) getActivity().getApplication();
    getActivity().getActionBar().setTitle(R.string.gatt_db);
    mgattListView = (ListView) rootView.findViewById(R.id.ListView_gatt_services);
    mTextHeading = (TextView) rootView.findViewById(R.id.txtservices);
    mTextHeading.setText(getString(R.string.gatt_descriptors_heading));
    mBackButton = (ImageView) rootView.findViewById(R.id.imgback);
    mBluetoothGattCharacteristic = mApplication.getBluetoothgattcharacteristic();

    // Back button listener
    mBackButton.setOnClickListener(new View.OnClickListener() {

        @Override//from ww w . j  a va 2 s.  c  o m
        public void onClick(View v) {
            getActivity().onBackPressed();

        }
    });

    // Getting the selected service from the arguments
    Bundle bundle = this.getArguments();
    if (bundle != null) {
        mGattServiceName = bundle.getString(Constants.GATTDB_SELECTED_SERVICE);
        mGattCharacteristicName = bundle.getString(Constants.GATTDB_SELECTED_CHARACTERISTICE);
    }
    //Preparing list data
    mBluetoothGattDescriptors = mBluetoothGattCharacteristic.getDescriptors();
    GattCharacteristicDescriptorsAdapter gattCharacteristicDescriptorsAdapter = new GattCharacteristicDescriptorsAdapter(
            getActivity(), mBluetoothGattDescriptors);
    if (gattCharacteristicDescriptorsAdapter != null) {
        mgattListView.setAdapter(gattCharacteristicDescriptorsAdapter);
    }
    mgattListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Logger.i("Descriptor selected " + mBluetoothGattDescriptors.get(position).getUuid());
            mApplication.setBluetoothgattdescriptor(mBluetoothGattDescriptors.get(position));
            FragmentManager fragmentManager = getFragmentManager();
            GattDescriptorDetails gattDescriptorDetails = new GattDescriptorDetails().create();
            fragmentManager.beginTransaction().add(R.id.container, gattDescriptorDetails).addToBackStack(null)
                    .commit();
        }
    });
    return rootView;
}

From source file:com.autoparts.buyers.action_content.ExamplesActivity.java

public void updateContent(Uri uri) {
    final Fragment fragment;
    final String tag;

    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction tr = fm.beginTransaction();

    if (!currentUri.equals(uri)) {
        final Fragment currentFragment = fm.findFragmentByTag(currentContentFragmentTag);
        if (currentFragment != null)
            tr.hide(currentFragment);/*ww  w.  j  a va2  s .  com*/
    }

    if (ModelFragment.ABOUT_URI.equals(uri)) {
        tag = ModelFragment.TAG;
        final Fragment foundFragment = fm.findFragmentByTag(tag);
        if (foundFragment != null) {
            fragment = foundFragment;
        } else {
            fragment = new ModelFragment(null);
        }
    } else if (uri != null) {
        tag = WebViewFragment.TAG;
        final WebViewFragment webViewFragment;
        final Fragment foundFragment = fm.findFragmentByTag(tag);
        if (foundFragment != null) {
            fragment = foundFragment;
            webViewFragment = (WebViewFragment) fragment;
        } else {
            webViewFragment = new WebViewFragment();
            fragment = webViewFragment;
        }
        webViewFragment.setUrl(uri.toString());
    } else {
        return;
    }

    if (fragment.isAdded()) {
        tr.show(fragment);
    } else {
        tr.replace(R.id.content, fragment, tag);
    }
    tr.commit();

    currentUri = uri;
    currentContentFragmentTag = tag;
}

From source file:com.cerema.cloud2.ui.activity.LogHistoryActivity.java

/**
 * Show loading dialog// www  .j a v  a  2  s .com
 */
public void showLoadingDialog() {
    // Construct dialog
    LoadingDialog loading = new LoadingDialog(getResources().getString(R.string.log_progress_dialog_text));
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    loading.show(ft, DIALOG_WAIT_TAG);
}