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

The following are Jave code examples for showing how to use commit() of the android.support.v4.app.FragmentTransaction class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Renrentou   File: DeviceHotListActivityDeprecated.java   View Source Code Vote up 6 votes
private void initCitySelect(){
    citySelectFragment = CitySelectFragment.newInstance(new CitySelectFragment.OnSelectCity() {
        @Override
        public void onSelectCity(String disCode) {
            pullToRefreshLayout.showView(ViewStatus.LOADING_STATUS);

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    list.clear();
                    getData();
                    pullToRefreshLayout.showView(ViewStatus.CONTENT_STATUS);
                    deviceAdapter.notifyDataSetChanged();
                }
            }, 2000);
        }
    });
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(R.id.city_fragment_container, citySelectFragment);
    ft.commit();
}
 
Example 2
Project: Renrentou   File: HomeFragment.java   View Source Code Vote up 6 votes
private void initFragment(){
    homeMyFragment = HomeMyFragment.newInstance();
    homeMyFragment.setOnRefresh(new HomeMyFragment.OnRefresh() {
        @Override
        public void success() {
            pullToRefreshLayout.finishRefresh();
        }

        @Override
        public void error() {
            pullToRefreshLayout.finishRefresh();
            showToast("加载失败,请重试");
        }
    });
    FragmentManager fm = getChildFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(R.id.home_fragment_container, homeMyFragment);
    ft.commit();
}
 
Example 3
Project: JinsMemeBRIDGE-Android   File: MainActivity.java   View Source Code Vote up 6 votes
void transitToFragment(Fragment next) {
  setUIPaused(false);
  InputMethodManager imm = (InputMethodManager) getSystemService(
      Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(mainLayout.getWindowToken(),
      InputMethodManager.HIDE_NOT_ALWAYS);

  FragmentManager manager = getSupportFragmentManager();
  FragmentTransaction transaction = manager.beginTransaction();
  transaction
      .setCustomAnimations(R.anim.config_in, android.R.anim.fade_out, android.R.anim.fade_in,
          R.anim.config_out2);
  transaction.replace(R.id.container, next);
  transaction.addToBackStack(null);
  transaction.commit();
}
 
Example 4
Project: cniao5   File: FragmentTabHost.java   View Source Code Vote up 6 votes
public void addTab(TabSpec tabSpec, Class<?> clss, Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mContext));
    String tag = tabSpec.getTag();

    TabInfo info = new TabInfo(tag, clss, args);

    if (mAttached) {
        // If we are already attached to the window, then check to make
        // sure this tab's fragment is inactive if it exists. This shouldn't
        // normally happen.
        info.fragment = mFragmentManager.findFragmentByTag(tag);
        if (info.fragment != null && !info.fragment.isDetached()) {
            FragmentTransaction ft = mFragmentManager.beginTransaction();
            //				ft.detach(info.fragment);
            ft.hide(info.fragment);
            ft.commit();
        }
    }

    mTabs.add(info);
    addTab(tabSpec);
}
 
Example 5
Project: open-rmbt   File: RMBTMainActivity.java   View Source Code Vote up 6 votes
public void showUrl(final String url, boolean popBackStack, String titleId)
{
	if (popBackStack) {
		popBackStackFull();
	}
    
	FragmentTransaction ft;
	
    
    ft = fm.beginTransaction();
    
    final Fragment fragment = new RMBTHelpFragment();        
    final Bundle args = new Bundle();
        
    args.putString(RMBTHelpFragment.ARG_URL, url);
    fragment.setArguments(args);
    ft.replace(R.id.fragment_content, fragment, titleId);
    ft.addToBackStack(titleId);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    ft.commit();
    refreshActionBar(titleId);
}
 
Example 6
Project: MyLife   File: MainActivity.java   View Source Code Vote up 6 votes
/**
 * 切换tab页
 * @param itemLayout
 */
public void onTabSelect(LinearLayout itemLayout) {
    int id = itemLayout.getId();
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    hideFragments(manager, transaction);

    //下面图标颜色变化
    for (int i = 0; i < mLayouts.length; i++) {
        mLayouts[i].setSelected(false);
    }
    itemLayout.setSelected(true);

    if (id == R.id.layout_home) {
        selectedFragment(transaction, mHomeFragment, Main0Fragment.class, FRAGMENT_TAG_HOME);
    } else if (id == R.id.layout_categorize) {
        selectedFragment(transaction, mCategorizeFragment, Main1Fragment.class, FRAGMENT_TAG_Categorize);
    }  else if (id == R.id.layout_more) {
        selectedFragment(transaction, mPersonFragment, Main2Fragment.class, FRAGMENT_TAG_PERSON);
    }
    transaction.commit();
}
 
Example 7
Project: Goalie_Android   File: ProfileActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    mUsername = getIntent().getStringExtra("username");
    if (savedInstanceState != null) {
        mUsername = savedInstanceState.getString("username");
    }

    FragmentManager fm = getSupportFragmentManager();
    ProfileFragment profileFragment = (ProfileFragment) fm.findFragmentByTag("profileFragment");
    if (profileFragment == null) {
        FragmentTransaction ft = fm.beginTransaction();
        profileFragment = ProfileFragment.newInstance();
        ft.add(android.R.id.content, profileFragment, "profileFragment");
        ft.commit();
    }

    // Create the presenter
    new ProfileFragmentPresenter(mUsername, profileFragment);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
}
 
Example 8
Project: smart-asset-iot-android-demo   File: BaseFragmentActivity.java   View Source Code Vote up 5 votes
@Override
public void addFragment(Fragment f, String tag, boolean isAddToBackStack) {
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.fragment_container, f);
    if (isAddToBackStack) {
        fragmentTransaction.addToBackStack(tag);
    }

    fragmentTransaction.commit();
}
 
Example 9
Project: RoomDemo2017   File: BaseActivity.java   View Source Code Vote up 5 votes
public static void addFragmentToActivity (FragmentManager fragmentManager,
                                          Fragment fragment,
                                          int frameId,
                                          String tag) {

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(frameId, fragment, tag);
    transaction.commit();
}
 
Example 10
Project: phonk   File: BaseActivity.java   View Source Code Vote up 5 votes
public void addFragment(Fragment fragment, int fragmentPosition, String tag, boolean addToBackStack) {
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
    ft.add(fragmentPosition, fragment, tag);
    // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    if (addToBackStack) {
        ft.addToBackStack(null);
    }
    ft.commit();
}
 
Example 11
Project: sealtalk-android-master   File: DoubleChatRoomActivity.java   View Source Code Vote up 5 votes
private void enterFragment1(Conversation.ConversationType mConversationType, String mTargetId) {

        ConversationFragment fragment = new ConversationFragment();

        Uri uri = Uri.parse("rong://" + getApplicationInfo().packageName).buildUpon()
                  .appendPath("conversation").appendPath(mConversationType.getName().toLowerCase())
                  .appendQueryParameter("targetId", mTargetId).build();

        fragment.setUri(uri);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.temp1, fragment);
        transaction.commit();
    }
 
Example 12
Project: schulcloud-mobile-android   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public void showFragment(@NonNull MainFragment fragment, int oldTabIndex, int newTabIndex) {
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (newTabIndex > oldTabIndex)
        transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
    else if (newTabIndex < oldTabIndex)
        transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
    transaction.replace(R.id.content, fragment);
    transaction.commit();
}
 
Example 13
Project: Barcode-Reader   File: BarcodeFragmentTestActivity.java   View Source Code Vote up 5 votes
@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();
}
 
Example 14
Project: mapbook-android   File: ActivityUtils.java   View Source Code Vote up 5 votes
/**
 * The {@code fragment} is added to the container view with id {@code tag}. The operation is
 * performed by the {@code fragmentManager}.
 *
 */
public static void addFragmentToActivity (final FragmentManager fragmentManager,
    final Fragment fragment, final String tag) {
  checkNotNull(fragmentManager);
  checkNotNull(fragment);
  final FragmentTransaction transaction = fragmentManager.beginTransaction();
  transaction.add(fragment, tag);
  transaction.commit();
}
 
Example 15
Project: GitHub   File: BaseFragment.java   View Source Code Vote up 5 votes
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        boolean isSupportHidden = savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN);
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        if (isSupportHidden) {
            ft.hide(this);
        } else {
            ft.show(this);
        }
        ft.commit();
    }
    Log.d(TAG, "onCreate: ");
}
 
Example 16
Project: LianXiZhihu   File: MainActivity.java   View Source Code Vote up 5 votes
private void showBookmarksFragment() {

        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.show(bookmarksFragment);
        fragmentTransaction.hide(mainFragment);
        fragmentTransaction.commit();

        toolbar.setTitle(getResources().getString(R.string.nav_bookmarks));

        if (bookmarksFragment.isAdded()) {
            bookmarksFragment.notifyDataChanged();
        }

    }
 
Example 17
Project: AssistantBySDK   File: BaseActivity.java   View Source Code Vote up 4 votes
public static void addFragmentToActivity(FragmentManager fragmentManager,
                                         Fragment fragment, int frameId) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);
    transaction.commit();
}
 
Example 18
Project: gamer-inside   File: ActivityUtils.java   View Source Code Vote up 4 votes
public static void detachFragmentFromActivity(@NonNull FragmentManager fragmentManager,
                                              @NonNull Fragment fragment) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.detach(fragment);
    transaction.commit();
}
 
Example 19
Project: Acg   File: ActivityUtils.java   View Source Code Vote up 4 votes
public static void addFragmentToActivity(FragmentManager fragmentManager, Fragment fragment, int frameId) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);
    transaction.commit();
}
 
Example 20
Project: MyCleanArchitecture   File: ActivityUtil.java   View Source Code Vote up 4 votes
public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager,
                                         @NonNull Fragment fragment, int frameId) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);
    transaction.commit();
}