List of usage examples for android.support.v4.app FragmentTransaction detach
public abstract FragmentTransaction detach(Fragment fragment);
From source file:de.stkl.gbgvertretungsplan.activities.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position, Object selItem) { // update the main_activity content by replacing fragments FragmentManager fragmentManager = getSupportFragmentManager(); Fragment frag = null;//ww w . ja va 2 s.c o m if (BuildConfig.DEBUG) Log.i(LOG_TAG, "Selected item: " + String.valueOf(position)); FragmentTransaction ft = fragmentManager.beginTransaction(); if (curFragment != null) ft.detach(curFragment); int CId = mNavigationDrawerFragment != null ? mNavigationDrawerFragment.getItemCId(position) : -1; // sub items // unique id, that matches an item if (CId >= 0) selItem = mNavigationDrawerFragment.getItem(mNavigationDrawerFragment.getSectionForPosition(position)); // group headers if (selItem.equals(getString(R.string.title_sec_main))) { mTitle = getString(R.string.title_sec_main); frag = fragmentManager.findFragmentByTag("main"); if (frag == null) { frag = MainFragment.newInstance(0, mNavigationDrawerFragment, CId); ft.add(R.id.container, frag, "main"); } else { ((MainFragment) frag).setCId(CId); ft.attach(frag); } } else if (selItem.equals(getString(R.string.title_sec_options))) { mTitle = getString(R.string.title_sec_options); frag = fragmentManager.findFragmentByTag("settings"); if (frag == null) { frag = PlaceholderFragment.newInstance(1, CId); ft.add(R.id.container, frag, "settings"); } else { ft.attach(frag); } } else if (selItem.equals(getString(R.string.title_sec_about))) { mTitle = getString(R.string.title_sec_about); frag = fragmentManager.findFragmentByTag("about"); if (frag == null) { frag = AboutFragment.newInstance(2, mNavigationDrawerFragment, CId); ft.add(R.id.container, frag, "about"); } else { ft.attach(frag); } } ft.commit(); curFragment = frag; if (BuildConfig.DEBUG) Log.d(LOG_TAG, "onNavigationDrawerItemSelected: " + mTitle); /*switch (position) { case 0: mTitle = getString(R.string.title_sec_main); break; case 1: mTitle = getString(R.string.title_sec_options); break; case 2: mTitle = getString(R.string.title_sec_about); break; }*/ }
From source file:com.ubundude.timesheet.MainActivity.java
public void onTabChanged(String tag) { TabInfo newTab = (TabInfo) this.mapTabInfo.get(tag); if (mLastTab != newTab) { FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); }//from w ww .ja v a 2 s . com } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.args); ft.add(R.id.realtabcontent1, newTab.fragment, newTab.tag); //ft.add(R.id.realtabcontent2, ListViewFragment, "listview"); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); this.getSupportFragmentManager().executePendingTransactions(); } }
From source file:com.dreamsocket.widget.TabbedViewStack.java
public void selectID(String p_ID, ViewTransition p_transition) { if (p_ID != this.m_selectedID) { ViewTransition defaultTrans = this.m_defaultTransition == null ? TabbedViewStackDefaults.defaultTransition : this.m_defaultTransition; ViewTransition transition = p_transition == null ? defaultTrans : p_transition; FragmentTransaction ft = this.m_fragMgr.beginTransaction(); if (transition.in != -1) { ft.setCustomAnimations(transition.in, transition.out); }/* ww w . j av a 2s. c o m*/ if (this.getSelected() != null) { this.getSelected().m_addToViewEnabled = false; if (this.getSelected().selected() != null) ft.detach(this.getSelected().selected()); } this.m_selectedID = p_ID; if (this.getSelected() != null) { this.getSelected().m_addToViewEnabled = true; if (this.getSelected().selected() != null) ft.attach(this.getSelected().selected()); } ft.commit(); } }
From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.LoadPK.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.dialog_load_pk, container); load = (Button) view.findViewById(R.id.dialog_load_pk_load); load.setText(Util.__("Import")); address = (EditText) view.findViewById(R.id.dialog_load_pk_editText); getDialog().setTitle("Import from Text"); load.setOnClickListener(new View.OnClickListener() { @Override//from w w w . j a v a 2 s. c o m public void onClick(View v) { strAddress = address.getText().toString(); //Interpret String body = DD.extractMessage(strAddress); //extractMessage(strAddress); if (body == null) { if (_DEBUG) Log.d(TAG, "LoadPK: Extraction of body failed"); Toast.makeText(getActivity(), "Separators not found: \"" + DD.SAFE_TEXT_MY_HEADER_SEP + DD.SAFE_TEXT_ANDROID_SUBJECT_SEP + DD.SAFE_TEXT_MY_BODY_SEP + "\"", Toast.LENGTH_SHORT).show(); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.detach(LoadPK.this); ft.commit(); return; } net.ddp2p.common.util.StegoStructure imported_object = DD.interpreteASN1B64Object(body); //interprete(body); if (imported_object == null) { if (_DEBUG) Log.d(TAG, "LoadPK: Decoding failed"); Toast.makeText(getActivity(), "Failed to decode", Toast.LENGTH_SHORT).show(); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.detach(LoadPK.this); ft.commit(); return; } String interpretation = imported_object.getNiceDescription(); //ask confirm address.setText(interpretation); AlertDialog.Builder confirm = new AlertDialog.Builder(getActivity()); confirm.setTitle("Do you wish to load?"); confirm.setMessage(interpretation).setCancelable(false) .setPositiveButton("Yes", new MyDialog_OnClickListener(imported_object) { public void _onClick(DialogInterface dialog, int id) { Log.d("PK", "LoadPK: Trying to save"); StegoStructure imported_object = (StegoStructure) ctx; try { imported_object.save(); Toast.makeText(getActivity(), "Saving successful!", Toast.LENGTH_SHORT).show(); } catch (P2PDDSQLException e) { e.printStackTrace(); Log.d("PK", "LoadPK: Failed to save: " + e.getLocalizedMessage()); } FragmentTransaction ft = getActivity().getSupportFragmentManager() .beginTransaction(); ft.detach(LoadPK.this); ft.commit(); dialog.cancel(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { FragmentTransaction ft = getActivity().getSupportFragmentManager() .beginTransaction(); ft.detach(LoadPK.this); ft.commit(); dialog.cancel(); } }); AlertDialog confirmDialog = confirm.create(); confirmDialog.show(); } /* private String extractMessage(String strAddress) { //boolean DEBUG = true; String addressASN1B64; try { if (strAddress == null) { if (DEBUG) Log.d(TAG, "LoadPK: Address = null"); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.detach(LoadPK.this); ft.commit(); return null; } //strAddress = strAddress.trim(); if (DEBUG) Log.d(TAG, "LoadPK: Address="+strAddress); String[] __chunks = strAddress.split(Pattern.quote(DD.SAFE_TEXT_MY_BODY_SEP)); if (__chunks.length == 0 || __chunks[__chunks.length - 1] == null) { if (DEBUG) Log.d(TAG, "LoadPK: My top Body chunk = null"); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.detach(LoadPK.this); ft.commit(); return null; } if (__chunks.length > 1) { addressASN1B64 = __chunks[__chunks.length - 1]; addressASN1B64 = addressASN1B64.trim(); if (DEBUG) Log.d(TAG, "LoadPK: got Body=" + addressASN1B64); addressASN1B64 = Util.B64Join(addressASN1B64); if (DEBUG) Log.d(TAG, "LoadPK: got Body=" + addressASN1B64); return addressASN1B64; } String[] chunks = strAddress.split(Pattern.quote(DD.SAFE_TEXT_MY_HEADER_SEP)); if (chunks.length == 0 || chunks[chunks.length - 1] == null) { if (DEBUG) Log.d(TAG, "LoadPK: My Body chunk = null"); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.detach(LoadPK.this); ft.commit(); return null; } String body = chunks[chunks.length - 1]; if (DEBUG) Log.d(TAG, "LoadPK: Body="+body); String[] _chunks = strAddress.split(Pattern.quote(DD.SAFE_TEXT_ANDROID_SUBJECT_SEP)); if (_chunks.length == 0 || _chunks[_chunks.length - 1] == null) { if (DEBUG) Log.d(TAG, "LoadPK: Android Body chunk = null"); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.detach(LoadPK.this); ft.commit(); return null; } addressASN1B64 = _chunks[_chunks.length - 1]; addressASN1B64 = addressASN1B64.trim(); if (DEBUG) Log.d(TAG, "LoadPK: Body=" + addressASN1B64); addressASN1B64 = Util.B64Join(addressASN1B64); if (DEBUG) Log.d(TAG, "LoadPK: Body=" + addressASN1B64); return addressASN1B64; } catch (Exception e) { e.printStackTrace(); } return null; } // public StegoStructure getStegoStructure(BigInteger ASN1TAG) { // Log.d("Import", "BN = "+ ASN1TAG); // for (StegoStructure ss : DD.getAvailableStegoStructureInstances()) { // Log.d("Import", "Available = "+ ss+" ID="+""+ss.getSignShort()); // if (ASN1TAG.equals (new BigInteger(""+ss.getSignShort()))) { // try { // Log.d("Import", "Match"); // return (StegoStructure) ss.getClass().newInstance(); // } catch (Exception e) { // e.printStackTrace(); // } // } // } // return null; // } */ private net.ddp2p.common.util.StegoStructure interprete(String addressASN1B64) { byte[] msg = null; StegoStructure ss = null; try { Log.d("Import", addressASN1B64); msg = Util.byteSignatureFromString(addressASN1B64); Decoder dec = new Decoder(msg); // StegoStructure s2s = getStegoStructure(dec.getTagValueBN()); ss = DD.getStegoStructure(dec); if (ss == null) { Log.d("Import", "LoadPK. Use default stego"); ss = new DD_Address(); } //DD_Address da = ss.setBytes(msg); return ss; } catch (Exception e) { e.printStackTrace(); DD_SK dsk = new DD_SK(); Log.d("Import", "LoadPK. Try SK"); try { dsk.setBytes(msg); Log.d("Import", "LoadPK. got=" + dsk); return dsk; } catch (Exception e2) { e2.printStackTrace(); Log.d("Import", "LoadPK. err sk=" + e2.getLocalizedMessage()); } } return null; } }); return view; }
From source file:dat255.grupp06.bibbla.MainActivity.java
@Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { // Hide keyboard and spinner hideKeyboard();/*w w w.j a v a 2 s . c o m*/ setSupportProgressBarIndeterminateVisibility(false); // Detach the correct fragment. switch (tab.getPosition()) { case 0: ft.detach(searchFragment); break; case 1: ft.detach(profileFragment); profileFragment.cancelUpdate(); break; case 2: ft.detach(libraryFragment); break; } }
From source file:click.kobaken.rxirohaandroid_sample.view.activity.MainActivity.java
private void switchFragment(@NonNull Fragment fragment, String tag) { if (fragment.isAdded()) { return;//from w ww .jav a2 s. co m } final FragmentManager manager = getSupportFragmentManager(); final FragmentTransaction fragmentTransaction = manager.beginTransaction(); final Fragment currentFragment = manager.findFragmentById(R.id.container); if (currentFragment != null) { fragmentTransaction.detach(currentFragment); } if (fragment.isDetached()) { fragmentTransaction.attach(fragment); } else { fragmentTransaction.add(R.id.container, fragment, tag); } fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit(); }
From source file:org.cvasilak.jboss.mobile.app.activities.JBossServerRootActivity.java
@Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { // Select proper stack Stack<String> backStack = backStacks.get(tab.getTag()); // Get topmost fragment String tag = backStack.peek(); Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); // Detach it//from w ww .ja va 2s. c o m ft.detach(fragment); }
From source file:com.clemot.julian.easylib.EasyActivity.java
/** * Detach fragment/*from www. j av a 2s . com*/ * * @param lastFrag fragment * @param frag fragment */ public void detachFragment(Fragment lastFrag, Fragment frag) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.detach(frag); fragmentTransaction.commit(); fragmentManager.executePendingTransactions(); }
From source file:com.google.android.gcm.demo.ui.MainActivity.java
private void selectItem(int pos) { if (pos < 0 || pos >= mMainMenu.getEntries().length) { pos = 0;/* w w w .j av a 2s . c om*/ } String titlePrefix = getString(R.string.main_activity_title_prefix); getSupportActionBar().setTitle(titlePrefix + mMainMenu.getEntries()[pos]); String nextFragmentTag = "FRAGMENT_TAG_" + Integer.toString(pos); Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.container); if (currentFragment != null && nextFragmentTag.equals(currentFragment.getTag())) { return; } Fragment recycledFragment = getSupportFragmentManager().findFragmentByTag(nextFragmentTag); try { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (currentFragment != null) { transaction.detach(currentFragment); } if (recycledFragment != null) { transaction.attach(recycledFragment); } else { transaction.add(R.id.container, mMainMenu.createFragment(pos), nextFragmentTag); } transaction.commit(); getSupportFragmentManager().executePendingTransactions(); // The header takes the first position. mDrawerMenu.setItemChecked(pos + 1, true); getAppPreferences().edit().putInt(PREF_LAST_SCREEN_ID, pos).apply(); } catch (InstantiationException e) { Log.wtf(LoggingService.LOG_TAG, "Error while instantiating the selected fragment", e); } catch (IllegalAccessException e) { Log.wtf(LoggingService.LOG_TAG, "Error while instantiating the selected fragment", e); } }
From source file:net.globide.creepypasta_files_07.BookmarksActivity.java
/** * Attaches fragments as a user navigates through the listview. *//* ww w . j av a 2s . c o m*/ public void attachFrag(String tag) { // Set the TabInfo object to the tag being selected. mFiNewFrag = null; mFiNewFrag = (FragInfo) this.mHmFragInfo.get(tag); // Begin a fragment transaction. FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); if (mFiNewFrag != null) { // Case: the fragment was previously created... if (mFiNewFrag.fragment != null) { // Detach the fragment. ft.detach(mFiNewFrag.fragment); } } if (mFiNewFrag != null) { // Case: The fragment has not yet been created. if (mFiNewFrag.fragment == null) { // Instantiate the fragment and store the returned fragment // object in // the FragInfo's fragment property. mFiNewFrag.fragment = Fragment.instantiate(this, mFiNewFrag.clss.getName(), mFiNewFrag.args); // Add the fragment to the view through the frame layout. ft.add(R.id.flList, mFiNewFrag.fragment, mFiNewFrag.tag); } else { // If the fragment has been previously created, simply attach // it. ft.attach(mFiNewFrag.fragment); } } // Commit the transaction. ft.commit(); // Execute the transaction. this.getSupportFragmentManager().executePendingTransactions(); }