List of usage examples for android.app FragmentManager findFragmentByTag
public abstract Fragment findFragmentByTag(String tag);
From source file:com.flyingmain.CachingImage.util.ImageCache.java
/** * Locate an existing instance of this Fragment or if not found, create and * add it using FragmentManager./*from w ww . j a v a 2s . c o m*/ * * @param fm The FragmentManager manager to use. * @return The existing instance of the Fragment or the new instance if just * created. */ private static RetainFragment findOrCreateRetainFragment(android.app.FragmentManager fm) { //BEGIN_INCLUDE(find_create_retain_fragment) // Check to see if we have retained the worker fragment. RetainFragment mRetainFragment = (RetainFragment) fm.findFragmentByTag(TAG); // If not retained (or first time running), we need to create and add it. if (mRetainFragment == null) { mRetainFragment = new RetainFragment(); fm.beginTransaction().add(mRetainFragment, TAG).commitAllowingStateLoss(); } return mRetainFragment; //END_INCLUDE(find_create_retain_fragment) }
From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java
/** * Returns the current GuidedStepListFragment on the fragment transaction stack. * * @return The current GuidedStepListFragment, if any, on the fragment transaction stack. */// www. j a v a 2 s . c om public static GuidedStepListFragment getCurrentGuidedStepListFragment(FragmentManager fm) { Fragment f = fm.findFragmentByTag(TAG_LEAN_BACK_ACTIONS_FRAGMENT); if (f instanceof GuidedStepListFragment) { return (GuidedStepListFragment) f; } return null; }
From source file:com.liferay.social.activity.MainActivity.java
private void _replaceRightFragment(Fragment fragment, String tag) { FragmentManager manager = getFragmentManager(); Fragment replacement = manager.findFragmentByTag(tag); if (replacement == null) { replacement = fragment;// www .j a v a2 s. com } FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.right_fragment, replacement, tag); transaction.commit(); _drawer.closeDrawers(); }
From source file:com.liferay.social.activity.MainActivity.java
public void onCreate(Bundle state) { super.onCreate(state); setContentView(R.layout.main);/*w ww. j ava 2 s. com*/ _drawer = (DrawerLayout) findViewById(R.id.drawer); ListView menu = (ListView) findViewById(R.id.menu); String[] menuItems = getResources().getStringArray(R.array.menu_items); menu.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menuItems)); menu.setOnItemClickListener(this); FragmentManager manager = getFragmentManager(); Fragment fragment = manager.findFragmentByTag(UsersFragment.TAG); if (fragment == null) { FragmentTransaction transaction = manager.beginTransaction(); transaction.add(R.id.right_fragment, new UsersFragment(), UsersFragment.TAG); transaction.commit(); } }
From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java
/** * Adds the specified GuidedStepListFragment as content of Activity; no backstack entry is added so * the activity will be dismissed when BACK key is pressed. The method is typically called in * Activity.onCreate() when savedInstanceState is null. When savedInstanceState is not null, * the Activity is being restored, do not call addAsRoot() to duplicate the Fragment restored * by FragmentManager.// w w w.j a v a 2s .c o m * {@link #UI_STYLE_ACTIVITY_ROOT} is assigned. * <p/> * Note: currently fragments added using this method must be created programmatically rather * than via XML. * * @param activity The Activity to be used to insert GuidedStepListFragment. * @param fragment The GuidedStepListFragment to be inserted into the fragment stack. * @param id The id of container to add GuidedStepListFragment, can be android.R.id.content. * @return The ID returned by the call FragmentTransaction.commit, or -1 there is already * GuidedStepListFragment. */ public static int addAsRoot(Activity activity, GuidedStepListFragment fragment, int id) { // Workaround b/23764120: call getDecorView() to force requestFeature of ActivityTransition. activity.getWindow().getDecorView(); FragmentManager fragmentManager = activity.getFragmentManager(); if (fragmentManager.findFragmentByTag(TAG_LEAN_BACK_ACTIONS_FRAGMENT) != null) { Log.w(TAG, "Fragment is already exists, likely calling " + "addAsRoot() when savedInstanceState is not null in Activity.onCreate()."); return -1; } FragmentTransaction ft = fragmentManager.beginTransaction(); fragment.setUiStyle(UI_STYLE_ACTIVITY_ROOT); return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit(); }
From source file:com.sawyer.advadapters.app.adapters.nfjsonadapter.NFJSONAdapterActivity.java
@Override protected void initFrags() { super.initFrags(); FragmentManager manager = getFragmentManager(); mListFragment = (NFJSONAdapterFragment) manager.findFragmentByTag(TAG_ADAPTER_FRAG); if (mListFragment == null) { mListFragment = NFJSONAdapterFragment.newInstance(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.frag_container, mListFragment, TAG_ADAPTER_FRAG); transaction.commit();/*w w w .j a v a2 s .co m*/ } mAddDialogFragment = (AddJSONArrayDialogFragment) manager.findFragmentByTag(TAG_ADD_DIALOG_FRAG); if (mAddDialogFragment != null) { mAddDialogFragment.setEventListener(this); } }
From source file:org.mariotaku.twidere.util.SaveFileTask.java
@Override protected void onCancelled() { final FragmentManager fm = activity.getFragmentManager(); final DialogFragment fragment = (DialogFragment) fm.findFragmentByTag(PROGRESS_FRAGMENT_TAG); if (fragment != null && fragment.isVisible()) { fragment.dismiss();/* www .j a va2 s . com*/ } super.onCancelled(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.RemoveReservation.java
/** * If reservation was removed, attempt to update reservation fragment or at least inform user, that he should do that manually. * * @param success true if reservation is removed *//*from www. jav a 2s . co m*/ @Override protected void onPostExecute(Boolean success) { if (success) { if (activity instanceof NavigationActivity) { FragmentManager fm = activity.getFragmentManager(); ReservationFragment fragment = (ReservationFragment) fm.findFragmentByTag(ReservationFragment.TAG); if (fragment == null) fragment = (ReservationFragment) fm.findFragmentById(fragmentId); if (fragment != null) { fragment.updateData(); Toast.makeText(activity, activity.getString(R.string.reser_removed), Toast.LENGTH_SHORT).show(); } else { Log.e(TAG, "Agenda fragment not found!"); Toast.makeText(activity, activity.getString(R.string.reser_removed_update), Toast.LENGTH_LONG) .show(); } } } }
From source file:org.mariotaku.twidere.util.SaveFileTask.java
@Override protected void onPostExecute(final File result) { final FragmentManager fm = activity.getFragmentManager(); final DialogFragment fragment = (DialogFragment) fm.findFragmentByTag(PROGRESS_FRAGMENT_TAG); if (fragment != null) { fragment.dismiss();/*from w w w. ja v a2 s .c o m*/ } super.onPostExecute(result); if (result != null && result.exists()) { Toast.makeText(activity, R.string.saved_to_gallery, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(activity, R.string.error_occurred, Toast.LENGTH_SHORT).show(); } }
From source file:com.sawyer.advadapters.app.adapters.jsonadapter.JSONAdapterActivity.java
@Override protected void initFrags() { super.initFrags(); FragmentManager manager = getFragmentManager(); mListFragment = (JSONAdapterFragment) manager.findFragmentByTag(TAG_ADAPTER_FRAG); if (mListFragment == null) { mListFragment = JSONAdapterFragment.newInstance(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.frag_container, mListFragment, TAG_ADAPTER_FRAG); transaction.commit();//from w w w . j a v a 2s . c om } mAddDialogFragment = (AddJSONArrayDialogFragment) manager.findFragmentByTag(TAG_ADD_DIALOG_FRAG); if (mAddDialogFragment != null) { mAddDialogFragment.setEventListener(this); } }