android.support.v4.app.FragmentTransaction Java Examples

The following examples show how to use android.support.v4.app.FragmentTransaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From playa with MIT License 6 votes vote down vote up
/**
 * 创建 fragment
 */
public void createFragments() {
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    HomeFragment homeFragment = new HomeFragment();
    fragmentList.add(homeFragment);
    fragmentTransaction.add(R.id.fragment_container, homeFragment);

    ProjectFragment projectFragment = new ProjectFragment();
    fragmentList.add(projectFragment);
    fragmentTransaction.add(R.id.fragment_container, projectFragment);

    HierarchyFragment hierarchyFragment = new HierarchyFragment();
    fragmentList.add(hierarchyFragment);
    fragmentTransaction.add(R.id.fragment_container, hierarchyFragment);

    NavigationFragment navigationFragment = new NavigationFragment();
    fragmentList.add(navigationFragment);
    fragmentTransaction.add(R.id.fragment_container, navigationFragment);

    MineFragment mineFragment = new MineFragment();
    fragmentList.add(mineFragment);
    fragmentTransaction.add(R.id.fragment_container, mineFragment);

    fragmentTransaction.commit();
}
 
Example #2
Source File: CategoryHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void onClickCategory(Category category) {
    FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
    Fragment fragment;
    fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(AddCategoryFragment.class.getSimpleName());
    if (fragment == null)
        fragment = new AddCategoryFragment();
    if (!fragment.isAdded()) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("category", category);
        bundle.putBoolean("edit", true);
        fragment.setArguments(bundle);
        Log.d("name", fragment.getClass().getSimpleName() + "");
        fragmentTransaction.add(((CategoryActivity) context).binding.categoryFl.getId(), fragment, fragment.getClass().getSimpleName());
        fragmentTransaction.addToBackStack(fragment.getClass().getSimpleName()).commit();
    }
}
 
Example #3
Source File: PhotoAlbumActivity.java    From Android with MIT License 6 votes vote down vote up
/**
 * View the photo album pictures
 */
public void gridListInfos() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if(galleryFragment!=null){
        fragmentTransaction.hide(galleryFragment);
    }
    if (gridFragment == null) {
        gridFragment = AlbumGridFragment.newInstance();
        fragmentTransaction.add(R.id.framelayout, gridFragment);
    } else {
        gridFragment.setData();
        fragmentTransaction.show(gridFragment);
    }
    //java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    fragmentTransaction.commit();
}
 
Example #4
Source File: MainActivity.java    From FloatingActionButton with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    mDrawerLayout.closeDrawer(GravityCompat.START);

    Fragment fragment = null;
    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    switch (item.getItemId()) {
        case R.id.home:
            fragment = new HomeFragment();
            break;
        case R.id.menus:
            fragment = new MenusFragment();
            break;
        case R.id.progress:
            fragment = new ProgressFragment();
            break;
    }

    ft.replace(R.id.fragment, fragment).commit();
    return true;
}
 
Example #5
Source File: FragmentPage2.java    From quickmark with MIT License 6 votes vote down vote up
/**
 * ����ˡ��ҵĿռ䡱��ť
 */
public static void clickHomeBtn() {
	// ʵ����Fragmentҳ��
	fragmentPage3 = new FragmentPage3();
	// �õ�Fragment���������
	FragmentTransaction fragmentTransaction = act
			.getSupportFragmentManager().beginTransaction();
	// �滻��ǰ��ҳ��
	fragmentTransaction.replace(R.id.frame_content, fragmentPage3);
	// ��������ύ
	fragmentTransaction.commit();

	friendfeedFl.setSelected(false);
	friendfeedIv.setSelected(false);

	myfeedFl.setSelected(false);
	myfeedIv.setSelected(false);

	homeFl.setSelected(true);
	homeIv.setSelected(true);

	moreFl.setSelected(false);
	moreIv.setSelected(false);
}
 
Example #6
Source File: TabPagerAdapter.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    Fragment fragment = fragments.get(position);
    if(!fragment.isAdded()){ // 如果fragment还没有added
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.add(fragment, "tab_" + position);
        ft.commit();
        /**
         * 在用FragmentTransaction.commit()方法提交FragmentTransaction对象后
         * 会在进程的主线程中,用异步的方式来执行。
         * 如果想要立即执行这个等待中的操作,就要调用这个方法(只能在主线程中调用)。
         * 要注意的是,所有的回调和相关的行为都会在这个调用中被执行完成,因此要仔细确认这个方法的调用位置。
         */
        fragmentManager.executePendingTransactions();
    }

    if(fragment.getView().getParent() == null){
        container.addView(fragment.getView()); // 为viewpager增加布局
    }

    return fragment.getView();
}
 
Example #7
Source File: SettingsActivity.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Switch to a specific Fragment with taking care of validation, Title and BackStack
 */
private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
                                  boolean addToBackStack, int titleResId, CharSequence title,
                                  boolean withTransition) {
    if (validate && !isValidFragment(fragmentName)) {
        String message = "Invalid fragment for this activity: " + fragmentName;
        throw new IllegalArgumentException(message);
    }

    Fragment f = Fragment.instantiate(this, fragmentName, args);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(android.R.id.content, f);

    if (withTransition && Device.hasKitKatApi())
        TransitionManager.beginDelayedTransition(mContent);
    if (addToBackStack) transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
    if (titleResId > 0) {
        transaction.setBreadCrumbTitle(titleResId);
    } else if (title != null) {
        transaction.setBreadCrumbTitle(title);
    }

    transaction.commitAllowingStateLoss();
    getFragmentManager().executePendingTransactions();
    return f;
}
 
Example #8
Source File: MainActivity.java    From jus with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	// default view is volley
	FragmentManager fragmentManager = getSupportFragmentManager();
	FragmentTransaction transaction = fragmentManager.beginTransaction();
	transaction.add(R.id.container, VolleyFragment.newInstance()).commit();

	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	setSupportActionBar(toolbar);

	DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
	ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
			this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

	drawer.setDrawerListener(toggle);
	toggle.syncState();

	NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
	navigationView.setNavigationItemSelectedListener(this);
}
 
Example #9
Source File: VideoMainActivity.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    Fragment fragment = fragments.get(position);
    if (!fragment.isAdded()) { // 如果fragment还没有added
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.add(fragment, "tab_" + position);
        ft.commit();
        /**
         * 在用FragmentTransaction.commit()方法提交FragmentTransaction对象后
         * 会在进程的主线程中,用异步的方式来执行。
         * 如果想要立即执行这个等待中的操作,就要调用这个方法(只能在主线程中调用)。
         * 要注意的是,所有的回调和相关的行为都会在这个调用中被执行完成,因此要仔细确认这个方法的调用位置。
         */
        fragmentManager.executePendingTransactions();
    }

    if (fragment.getView().getParent() == null) {
        container.addView(fragment.getView()); // 为viewpager增加布局
    }

    return fragment.getView();
}
 
Example #10
Source File: FilterFragment.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
public static void showFilterDialog(FragmentManager fm, boolean isMuzei) {
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(TAG);
    if (prev != null) {
        ft.remove(prev);
    }

    ft.add(newInstance(isMuzei), TAG)
            .setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    try {
        ft.commit();
    } catch (IllegalStateException e) {
        ft.commitAllowingStateLoss();
    }
}
 
Example #11
Source File: BaseFragment.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    log("onCreate");
    super.onCreate(savedInstanceState);
    FragmentManager fm = getFragmentManager();
    if (fm == null) return;
    if (savedInstanceState != null) {
        boolean isSupportHidden = savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN);
        FragmentTransaction ft = fm.beginTransaction();
        if (isSupportHidden) {
            ft.hide(this);
        } else {
            ft.show(this);
        }
        ft.commitAllowingStateLoss();
    }
    Bundle bundle = getArguments();
    initData(bundle);
}
 
Example #12
Source File: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param uid
 */
public void showResultDetail(final String testUUid)
{    	
    FragmentTransaction ft;
    
    final Fragment fragment = new RMBTTestResultDetailFragment();
    
    final Bundle args = new Bundle();
    
    args.putString(RMBTTestResultDetailFragment.ARG_UID, testUUid);
    fragment.setArguments(args);
    
    ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_RESULT_DETAIL);
    ft.addToBackStack(AppConstants.PAGE_TITLE_RESULT_DETAIL);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();
    
    refreshActionBar(AppConstants.PAGE_TITLE_RESULT_DETAIL);
}
 
Example #13
Source File: CommentsTimeLinePagerAdapter.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public CommentsTimeLinePagerAdapter(CommentsTimeLineFragment fragment, ViewPager viewPager, FragmentManager fm,
                                    SparseArray<Fragment> fragmentList) {
    super(fm);
    this.fragmentList = fragmentList;
    fragmentList.append(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION,
            fragment.getCommentsToMeTimeLineFragment());
    fragmentList.append(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION,
            fragment.getCommentsByMeTimeLineFragment());
    FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction();
    if (!fragmentList.get(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION).isAdded())
        transaction.add(viewPager.getId(), fragmentList.get(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION),
                CommentsToMeTimeLineFragment.class.getName());
    if (!fragmentList.get(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION).isAdded())
        transaction.add(viewPager.getId(), fragmentList.get(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION),
                CommentsByMeTimeLineFragment.class.getName());
    if (!transaction.isEmpty()) {
        transaction.commit();
        fragment.getChildFragmentManager().executePendingTransactions();
    }
}
 
Example #14
Source File: IBaseActivity.java    From Collection-Android with MIT License 6 votes vote down vote up
/**
 * When the back off.
 */
private boolean onBackStackFragment() {
	if (mFragmentStack.size() > 1) {
		mFManager.popBackStack();
		IBaseFragment inFragment = mFragmentStack.get(mFragmentStack.size() - 2);
		FragmentTransaction fragmentTransaction = mFManager.beginTransaction();
		fragmentTransaction.show(inFragment);
		fragmentTransaction.commit();
		IBaseFragment outFragment= mFragmentStack.get(mFragmentStack.size() - 1);
		inFragment.onResume();
		FragmentStackEntity stackEntity = (FragmentStackEntity) mFragmentEntityMap.get(outFragment);
		mFragmentStack.remove(outFragment);
		mFragmentEntityMap.remove(outFragment);
		fragmentStack.remove(outFragment.getClass().getSimpleName());
		if (stackEntity!=null&&stackEntity.requestCode != REQUEST_CODE_INVALID) {
			inFragment.onFragmentResult(
					stackEntity.requestCode,
					stackEntity.resultCode,
					stackEntity.result
			);
		}
		return true;
	}
	return false;
}
 
Example #15
Source File: InAppBillingFragment.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
public static void showInAppBillingDialog(@NonNull FragmentManager fm, @NonNull String key, @NonNull String[] productId) {
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(TAG);
    if (prev != null) {
        ft.remove(prev);
    }

    ft.add(newInstance(key, productId), TAG)
            .setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    try {
        ft.commit();
    } catch (IllegalStateException e) {
        ft.commitAllowingStateLoss();
    }
}
 
Example #16
Source File: ActorTvShows.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	String actorId = getIntent().getExtras().getString("actorId");
	String actorName = getIntent().getExtras().getString("actorName");
       mToolbarColor = getIntent().getExtras().getInt(IntentKeys.TOOLBAR_COLOR);
	
	getSupportActionBar().setSubtitle(actorName);

	Fragment frag = getSupportFragmentManager().findFragmentByTag(TAG);
	if (frag == null && savedInstanceState == null) {
		final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		ft.replace(R.id.content, ActorTvShowsFragment.newInstance(actorId), TAG);
		ft.commit();
	}
}
 
Example #17
Source File: WizardActivity.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);

	informaCam =  InformaCam.getInstance();
	
	if(PreferenceManager.getDefaultSharedPreferences(this).getBoolean("prefBlockScreenshots", false))
	{
  		getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
  				WindowManager.LayoutParams.FLAG_SECURE);      
	}
	
	setContentView(R.layout.activity_wizard);

	Fragment step1 = Fragment.instantiate(this, WizardSelectLanguage.class.getName());

	FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
	ft.add(R.id.wizard_holder, step1);
	//ft.addToBackStack(null);
	ft.commit();
	
	checkForCrashes();
	checkForUpdates();
}
 
Example #18
Source File: MainActivity.java    From admob-native-advanced-feed with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        // Create new fragment to display a progress spinner while the data set for the
        // RecyclerView is populated.
        Fragment loadingScreenFragment = new LoadingScreenFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.fragment_container, loadingScreenFragment);

        // Commit the transaction.
        transaction.commit();

        // Update the RecyclerView item's list with menu items.
        addMenuItemsFromJson();

        loadMenu();
    }
}
 
Example #19
Source File: ActionBarWrapper.java    From zen4android with MIT License 6 votes vote down vote up
@Override
public void onTabReselected(android.app.ActionBar.Tab tab, android.app.FragmentTransaction ft) {
    if (mListener != null) {
        FragmentTransaction trans = null;
        if (mActivity instanceof FragmentActivity) {
            trans = ((FragmentActivity)mActivity).getSupportFragmentManager().beginTransaction()
                    .disallowAddToBackStack();
        }

        mListener.onTabReselected(this, trans);

        if (trans != null && !trans.isEmpty()) {
            trans.commit();
        }
    }
}
 
Example #20
Source File: ActorDetails.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

       // Set theme
       setTheme(R.style.Mizuu_Theme_NoBackground);

       ViewUtils.setupWindowFlagsForStatusbarOverlay(getWindow(), true);

       setTitle(null);
	
	String actorId = getIntent().getExtras().getString("actorID");

	Fragment frag = getSupportFragmentManager().findFragmentByTag(TAG);
	if (frag == null && savedInstanceState == null) {
		final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		ft.replace(android.R.id.content, ActorDetailsFragment.newInstance(actorId), TAG);
		ft.commit();
	}
}
 
Example #21
Source File: NumberConverterActivity.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_base_converter);
    setupToolbar();
    setTitle(R.string.tab_title_base);

    BaseConverterFragment baseFragment
            = (BaseConverterFragment) getSupportFragmentManager().findFragmentByTag(BaseConverterFragment.class.getName());
    if (baseFragment == null) {
        baseFragment = BaseConverterFragment.newInstance();
    }
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.content, baseFragment, BaseConverterFragment.class.getName());
    fragmentTransaction.commit();
}
 
Example #22
Source File: SlideDayTimePicker.java    From SlideDayTimePicker with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of {@code SlideDayTimePicker}.
 *
 * @param fm  The {@code FragmentManager} from the calling activity that is used
 *            internally to show the {@code DialogFragment}.
 */
public SlideDayTimePicker(FragmentManager fm)
{
    // See if there are any DialogFragments from the FragmentManager
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(SlideDayTimeDialogFragment.TAG_SLIDE_DAY_TIME_DIALOG_FRAGMENT);

    // Remove if found
    if (prev != null)
    {
        ft.remove(prev);
        ft.commit();
    }

    mFragmentManager = fm;
}
 
Example #23
Source File: SlideDateTimePicker.java    From SlideDateTimePicker with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of {@code SlideDateTimePicker}.
 *
 * @param fm  The {@code FragmentManager} from the calling activity that is used
 *            internally to show the {@code DialogFragment}.
 */
public SlideDateTimePicker(FragmentManager fm)
{
    // See if there are any DialogFragments from the FragmentManager
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(SlideDateTimeDialogFragment.TAG_SLIDE_DATE_TIME_DIALOG_FRAGMENT);

    // Remove if found
    if (prev != null)
    {
        ft.remove(prev);
        ft.commit();
    }

    mFragmentManager = fm;
}
 
Example #24
Source File: NavigationActivity.java    From KernelAdiutor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void finish() {
    super.finish();
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    for (int id : mActualFragments.keySet()) {
        Fragment fragment = fragmentManager.findFragmentByTag(id + "_key");
        if (fragment != null) {
            fragmentTransaction.remove(fragment);
        }
    }
    fragmentTransaction.commitAllowingStateLoss();
    if (mAdsFetcher != null) {
        mAdsFetcher.cancel();
    }
    RootUtils.closeSU();
}
 
Example #25
Source File: MainActivity.java    From scallop with MIT License 6 votes vote down vote up
/**
 * 创建 fragment
 */
public void createFragments() {
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    HomeFragment homeFragment = new HomeFragment();
    fragmentList.add(homeFragment);
    fragmentTransaction.add(R.id.fragment_container, homeFragment);

    XianDuFragment xianDuFragment = new XianDuFragment();
    fragmentList.add(xianDuFragment);
    fragmentTransaction.add(R.id.fragment_container, xianDuFragment);

    PicturesFragment picturesFragment = new PicturesFragment();
    fragmentList.add(picturesFragment);
    fragmentTransaction.add(R.id.fragment_container, picturesFragment);

    MoreFragment moreFragment = new MoreFragment();
    fragmentList.add(moreFragment);
    fragmentTransaction.add(R.id.fragment_container, moreFragment);

    fragmentTransaction.commit();
}
 
Example #26
Source File: StorageBrowserFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public void browse (MediaWrapper media, int position, boolean scanned){
    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    Fragment next = createFragment();
    Bundle args = new Bundle();
    args.putParcelable(KEY_MEDIA, media);
    args.putBoolean(KEY_IN_MEDIALIB, mScannedDirectory || scanned);
    next.setArguments(args);
    ft.replace(R.id.fragment_placeholder, next, media.getLocation());
    ft.addToBackStack(mMrl);
    ft.commit();
}
 
Example #27
Source File: BaseFragmentPagerAdapter.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
public void setFragments(ArrayList<Fragment> fragments) {
    if (this.fragments != null) {
        FragmentTransaction ft = fm.beginTransaction();
        for (Fragment f : this.fragments) {
            ft.remove(f);
        }
        ft.commit();
        ft = null;
        fm.executePendingTransactions();
    }
    this.fragments = fragments;
    notifyDataSetChanged();
}
 
Example #28
Source File: PicturesFragment.java    From abelana with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.fab_add_photo:
            final FragmentTransaction ft = getFragmentManager()
                    .beginTransaction();
            ft.addToBackStack(null);
            ft.replace(R.id.container, UploadFragment.newInstance());
            ft.commit();
            break;
        default:
            break;
    }
}
 
Example #29
Source File: MvcDialog.java    From AndroidMvc with Apache License 2.0 5 votes vote down vote up
/**
 * Show dialog.
 * @param fragmentManager The fragment manager. Usually it's the child fragment manager of the
 *                        fragment on which the dialog will show
 * @param dialogClass The class type of the dialog extending {@link MvcDialog}
 */
public static void show(FragmentManager fragmentManager, Class<? extends MvcDialog> dialogClass) {
    FragmentTransaction ft = fragmentManager.beginTransaction();
    MvcDialog dialogFragment = (MvcDialog) fragmentManager.findFragmentByTag(dialogClass.getName());
    if (dialogFragment == null) {
        try {
            dialogFragment = new ReflectUtils.newObjectByType<>(dialogClass).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    ft.addToBackStack(null);
    dialogFragment.show(ft, dialogClass.getName());
}
 
Example #30
Source File: BarcodeFragmentTestActivity.java    From Barcode-Reader with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_barcode_fragment_test);

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    BarcodeFragment bf = new BarcodeFragment();
    ft.add(R.id.container, bf);
    ft.commit();
}