Java Code Examples for android.support.v4.app.FragmentTransaction#commit()

The following examples show how to use android.support.v4.app.FragmentTransaction#commit() . 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: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param uid
 */
public void showExpandedResultDetail(QoSServerResultCollection testResultArray, DetailType detailType, int position)
{
    FragmentTransaction ft;
    
    //final RMBTResultDetailPagerFragment fragment = new RMBTResultDetailPagerFragment();
    final QoSCategoryPagerFragment fragment = new QoSCategoryPagerFragment();
    
    fragment.setQoSResult(testResultArray);
    fragment.setDetailType(detailType);
    
    ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_RESULT_QOS);
    ft.addToBackStack("result_detail_expanded");
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();
    
    fragment.setCurrentPosition(position);
    refreshActionBar(AppConstants.PAGE_TITLE_RESULT_QOS);
}
 
Example 2
Source File: MainActivity.java    From Retrofit2SampleApp with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FragmentManager fragmentManager = getSupportFragmentManager();

    if (fragmentManager.findFragmentByTag(SearchFragment.class.getName()) == null) {
        SearchFragment searchFragment = SearchFragment.newInstance();
        searchFragment.setRetainInstance(true);

        FragmentTransaction transaction = getSupportFragmentManager().
                beginTransaction().add(R.id.fragment_holder, searchFragment, SearchFragment.class.getName());

        transaction.commit();
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}
 
Example 3
Source File: MainActivity.java    From ListBuddies with Apache License 2.0 6 votes vote down vote up
private void manageFragment(Fragment newInstanceFragment, FragmentTags tag, boolean addToBackStack) {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment currentIntanceFragment = findFragmentByTag(tag);
    if (currentIntanceFragment == null || (currentIntanceFragment != null && currentIntanceFragment.isHidden())) {
        if (currentIntanceFragment != null) {
            ft.show(currentIntanceFragment);
        } else {
            currentIntanceFragment = newInstanceFragment;
            ft.add(R.id.container, currentIntanceFragment, tag.toString());
            if (addToBackStack) {
                ft.addToBackStack(null);
            }
        }
    } else {
        ft.hide(currentIntanceFragment);
        fm.popBackStack();
    }
    ft.commit();
}
 
Example 4
Source File: FragmentCompat.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 初始化fragment,list
 *
 * @param fragmentManager
 * @param containerId
 * @param showPosition
 * @param fragments
 */
public static void init(FragmentManager fragmentManager,
                        int containerId,
                        int showPosition,
                        List<Fragment> fragments) {
    FragmentTransaction ft = fragmentManager.beginTransaction();
    int size = fragments.size();
    for (int i = 0; i < size; i++) {
        Fragment fragment = fragments.get(i);

        String toName = fragment.getClass().getName();
        ft.add(containerId, fragment, toName);

        if (i != showPosition) {
            ft.hide(fragment);
        } else {
            fragment.onHiddenChanged(false);
        }
    }
    ft.commit();
}
 
Example 5
Source File: CurrencyFragment.java    From currency-picker-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    //do what you want to do when button is clicked
    switch (v.getId()) {
        case R.id.currency_picker_button:
            mCurrencyPicker.show(getFragmentManager(), "CURRENCY_PICKER");
            break;
        case R.id.openPreferences:
            Intent intent = new Intent(getActivity(), CurrencySettingsActivity.class);
            startActivity(intent);
            break;
        case R.id.openFragment:

            FragmentTransaction transaction = getFragmentManager().beginTransaction();

            transaction.replace(R.id.container, mCurrencyPicker, "currencyFragment");
            transaction.addToBackStack(null);

            transaction.commit();
            break;
    }
}
 
Example 6
Source File: ViewPagerFragmentAdapter.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public ViewPagerFragmentAdapter(Fragment fragment, ViewPager viewPager, FragmentManager fm, ArrayList<ChildPage> fragmentList) {
    super(fm);
    this.mFragmentList = fragmentList;

    FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction();

    for (int i = 0; i < fragmentList.size(); i++) {
        Fragment ft = this.mFragmentList.get(i).getmFragment();
        if (!ft.isAdded()) {
            transaction.add(viewPager.getId(), ft, ft.getClass().getName() + i);
        }
    }

    if (!transaction.isEmpty()) {
        transaction.commit();
        fragment.getChildFragmentManager().executePendingTransactions();
    }
}
 
Example 7
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 8
Source File: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
public void showSync()
{
    FragmentTransaction ft;        
    ft = fm.beginTransaction();
    
    final Fragment fragment = new RMBTSyncFragment();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_SYNC);
    ft.addToBackStack(AppConstants.PAGE_TITLE_SYNC);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);        	
    
    ft.commit();
    refreshActionBar(AppConstants.PAGE_TITLE_SYNC);
}
 
Example 9
Source File: ScreenController.java    From memory-game with Apache License 2.0 5 votes vote down vote up
public void openScreen(Screen screen) {
	mFragmentManager = Shared.activity.getSupportFragmentManager();
	
	if (screen == Screen.GAME && openedScreens.get(openedScreens.size() - 1) == Screen.GAME) {
		openedScreens.remove(openedScreens.size() - 1);
	} else if (screen == Screen.DIFFICULTY && openedScreens.get(openedScreens.size() - 1) == Screen.GAME) {
		openedScreens.remove(openedScreens.size() - 1);
		openedScreens.remove(openedScreens.size() - 1);
	}
	Fragment fragment = getFragment(screen);
	FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
	fragmentTransaction.replace(R.id.fragment_container, fragment);
	fragmentTransaction.commit();
	openedScreens.add(screen);
}
 
Example 10
Source File: MediaSourcePickDialogFragment.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void show(FragmentManager fragmentManager, String tag) {
    fragmentManager.popBackStack();

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    //add fragment to backstack for getting permission request result to this fragment
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.add(this, tag);
    fragmentTransaction.commit();
}
 
Example 11
Source File: FilePickerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.file_picker_activity);
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.fragment_placeholder, new FilePickerFragment(), "picker");
    ft.commit();
}
 
Example 12
Source File: FragmentMenuSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
void updateFragmentVisibility() {
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    if (mCheckBox1.isChecked()) ft.show(mFragment1);
    else ft.hide(mFragment1);
    if (mCheckBox2.isChecked()) ft.show(mFragment2);
    else ft.hide(mFragment2);
    ft.commit();
}
 
Example 13
Source File: MoviesAdapter.java    From Android with MIT License 5 votes vote down vote up
private void Fragment(Movie movie,Fragment getfragment,String TAG) {
    Fragment fragment = getfragment;
    Bundle bundle = new Bundle();
    bundle.putSerializable("movie", movie);
    fragment.setArguments(bundle);
    FragmentTransaction fragmentTransaction = ((FragmentActivity)mContext).getSupportFragmentManager().beginTransaction();
    /*fragmentTransaction.setCustomAnimations(android.R.anim.fade_in,
            android.R.anim.fade_out);*/
    fragmentTransaction.replace(R.id.frame, fragment,TAG );
    fragmentTransaction.addToBackStack(MainActivity.CURRENT_TAG);
    fragmentTransaction.commit();
}
 
Example 14
Source File: FragmentActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle bundle)
{
    super.onCreate(bundle);

    setContentView(R.layout.atom_ui_activity_blank);
    QtNewActionBar actionBar = (QtNewActionBar) findViewById(R.id.my_action_bar);
    setNewActionBar(actionBar);
    Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {

        if (intent.getExtras().containsKey(CONTENT)) {
            String fragmentName = intent.getExtras().getString(CONTENT);
            if (fragmentName != null) {
                Fragment fragment = Fragment.instantiate(this, fragmentName, intent.getExtras());

                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.layout_blanck_content, fragment);
                transaction.commit();
            }
        }
        String title = getIntent().getStringExtra(TITLE);
        if (!TextUtils.isEmpty(title)) {
            setActionBarTitle(title);
        }
    }
}
 
Example 15
Source File: FragmentTransactionUriRequest.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
@Override
public boolean startFragment(@NonNull UriRequest request, @NonNull Bundle bundle) throws ActivityNotFoundException, SecurityException {
    String fragmentClassName = request.getStringField(FragmentTransactionHandler.FRAGMENT_CLASS_NAME);
    if (TextUtils.isEmpty(fragmentClassName)) {
        Debugger.fatal("FragmentTransactionHandler.handleInternal()应返回的带有ClassName");
        return false;
    }
    if (mContainerViewId == 0) {
        Debugger.fatal("FragmentTransactionHandler.handleInternal()mContainerViewId");
        return false;
    }

    try {
        Fragment fragment = Fragment.instantiate(request.getContext(), fragmentClassName, bundle);
        if (fragment == null) {
            return false;
        }


        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        switch (mStartType) {
            case TYPE_ADD:
                transaction.add(mContainerViewId, fragment, mTag);
                break;
            case TYPE_REPLACE:
                transaction.replace(mContainerViewId, fragment, mTag);
                break;
        }
        if (mAllowingStateLoss) {
            transaction.commitAllowingStateLoss();
        } else {
            transaction.commit();
        }
        return true;
    } catch (Exception e) {
        Debugger.e("FragmentTransactionUriRequest",e);
        return false;
    }
}
 
Example 16
Source File: GeoARActivity.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
private void showFragment(Fragment fragment) {
	if (fragment.isAdded()) {
		return;
	}
	getSupportFragmentManager().executePendingTransactions();
	FragmentTransaction transaction = getSupportFragmentManager()
			.beginTransaction();
	transaction.replace(R.id.fragmentContainer, fragment);
	transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
	transaction.commit();
}
 
Example 17
Source File: MainActivity.java    From android-kubernetes-blockchain with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

    // use tech fragment - initial layout
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.frame_layout, TechFragment.newInstance());
    transaction.commit();

    // request queue
    queue = Volley.newRequestQueue(this);

    // check if location is permitted
    if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "access fine location not yet granted");
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
    }

    // initialize shared preferences - persistent data
    sharedPreferences = this.getSharedPreferences("shared_preferences_fitcoin", Context.MODE_PRIVATE);

    // Check if user is already enrolled
    if (sharedPreferences.contains("BlockchainUserId")) {
        Log.d(TAG, "User already registered.");
    } else {
            // register the user
            registerUser();
    }
}
 
Example 18
Source File: MainActivity.java    From WiFiProxySwitcher with Apache License 2.0 5 votes vote down vote up
@Override
public void onProxySetError() {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    wifiConnectionFragment = new WiFiConnectionFragment();
    ft.hide(proxySettingsFragment);
    ft.add(R.id.fragment_container, wifiConnectionFragment);
    ft.commit();
}
 
Example 19
Source File: BaseActivity.java    From JianDanRxJava with Apache License 2.0 4 votes vote down vote up
public void replaceFragment(@IdRes int id_content, Fragment fragment) {
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(id_content, fragment);
    transaction.commit();
}
 
Example 20
Source File: MainActivity.java    From ONE-Unofficial with Apache License 2.0 4 votes vote down vote up
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (homeFragment != null) {
        transaction.hide(homeFragment);
    }
    if (articleFragment != null) {
        transaction.hide(articleFragment);
    }
    if (questionFragment != null) {
        transaction.hide(questionFragment);
    }
    if (thingFragment != null) {
        transaction.hide(thingFragment);
    }
    if (personalFragment != null) {
        transaction.hide(personalFragment);
    }
    switch (checkedId) {
        case R.id.tab_home:
            if (homeFragment == null) {
                homeFragment = new HomeFragment();
                transaction.add(R.id.main_content, homeFragment);
            } else {
                transaction.show(homeFragment);
            }
            break;
        case R.id.tab_article:
            if (articleFragment == null) {
                articleFragment = new ArticleFragment();
                transaction.add(R.id.main_content, articleFragment);
            } else {
                transaction.show(articleFragment);
            }
            break;
        case R.id.tab_question:
            if (questionFragment == null) {
                questionFragment = new QuestionFragment();
                transaction.add(R.id.main_content, questionFragment);
            } else {
                transaction.show(questionFragment);
            }
            break;
        case R.id.tab_thing:
            if (thingFragment == null) {
                thingFragment = new ThingFragment();
                transaction.add(R.id.main_content, thingFragment);
            } else {
                transaction.show(thingFragment);
            }
            break;
        case R.id.tab_personal:
            if (personalFragment == null) {
                personalFragment = new PersonalFragment();
                transaction.add(R.id.main_content, personalFragment);
            } else {
                transaction.show(personalFragment);
            }
            break;
    }
    transaction.commit();
}