本文整理汇总了Java中android.support.v4.app.FragmentTransaction.add方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.add方法的具体用法?Java FragmentTransaction.add怎么用?Java FragmentTransaction.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
if (savedInstanceState == null) {
Fragment preferenceFragment = new BluetoothFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.pref_container, preferenceFragment);
ft.commit();
}
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
registerReceiver(new Service(), filter);
}
示例2: switchFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void switchFragment(NavButton oldNavButton, NavButton selectNav) {
FragmentTransaction transaction = mFragmentManager.beginTransaction();
if (oldNavButton != null) {
if (oldNavButton.getFragment() != null) {
transaction.detach(oldNavButton.getFragment());
}
}
if (selectNav != null) {
if (selectNav.getFragment() != null) {
transaction.attach(selectNav.getFragment());
} else {
// Fragment.instantiate工具方法,再也不用自己newInstance().
Fragment fragment = Fragment.instantiate(mContext, selectNav.getClx().getName(), null);
transaction.add(mContainerId, fragment, selectNav.getNavBtnTag());
selectNav.setFragment(fragment);
}
}
transaction.commit();
}
示例3: onShareDialogShow
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void onShareDialogShow(String jsonString) {
FragmentManager fm = getSupportFragmentManager();
if (fm != null) {
FragmentTransaction ft = fm.beginTransaction();
if (this.mShareProtocol == null) {
LeResponseMessage response = LeMessageManager.getInstance().dispatchMessage(new LeMessage(LeMessageIds.MSG_SHARE_WEBVIEW_INIT, new OnWebViewRefreshListener() {
public void onRefresh() {
LetvBaseWebViewActivity.this.refresh();
}
}));
if (LeResponseMessage.checkResponseMessageValidity(response, WebViewShareProtocol.class)) {
this.mShareProtocol = (WebViewShareProtocol) response.getData();
}
} else {
ft.remove(this.mShareProtocol.getFragment());
}
if (this.mShareProtocol != null) {
this.mShareProtocol.setDefaultShareText(this.mShareDefaultTitle, this.mShareDefaultDesc, getBaseUrl(), this.mShareDefaultIcon, this.baseUrl);
ft.add(this.mShareProtocol.getFragment(), "shareDialog");
this.mShareProtocol.setIsLoadComplete(this.loadFinish);
this.mShareProtocol.notifyShareLayout();
}
ft.commitAllowingStateLoss();
}
}
示例4: switchFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void switchFragment() {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.hide(mFragments[mCurrentTabIndex]);
if (mFragments[mIndex].isAdded()){
transaction.add(R.id.container, mFragments[mIndex]);
}
transaction.show(mFragments[mIndex]);
mCurrentTabIndex = mIndex;
}
示例5: addFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void addFragment(int[] layout, Fragment[] fragment) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
for (int i = 0; i < layout.length; i++) {
transaction.add(layout[i], fragment[i]);
}
transaction.commit();
}
示例6: enterFragment2
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void enterFragment2(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.temp2, fragment);
transaction.commit();
}
示例7: show
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public BaseNiceDialog show(FragmentManager manager) {
FragmentTransaction ft = manager.beginTransaction();
if (this.isAdded()) {
ft.remove(this).commit();
}
ft.add(this, String.valueOf(System.currentTimeMillis()));
ft.commitAllowingStateLoss();
return this;
}
示例8: addFilePreviewerFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void addFilePreviewerFragment(Bundle savedInstance) {
if (savedInstance == null) {
filePreviewerFragment = FilePreviewerFragment.newInstance(savedInstance);
FrameLayout fl = (FrameLayout) findViewById(R.id.filepreviewer_container);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(fl.getId(), filePreviewerFragment, FRAGMENT_FILE_PREVIEWER);
ft.commit();
} else {
filePreviewerFragment = (FilePreviewerFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_FILE_PREVIEWER);
}
}
示例9: setSelectFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void setSelectFragment(String search) {
FragmentManager manager = view.getMainActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
if (search == null) {
collectionFragment = manager.findFragmentByTag(TYPE_COLLECTION_TAG);
hideFragment(transaction);
if (null == collectionFragment) {
collectionFragment = CollectionFragment.newInstance();
transaction.add(R.id.fragment, collectionFragment, TYPE_COLLECTION_TAG);
} else {
transaction.show(collectionFragment);
}
} else {
view.setToolBar();
listFragment = manager.findFragmentByTag(TYPE_LIST_TAG);
hideFragment(transaction);
if (null == listFragment) {
listFragment = TabFragment.newInstance(search);
transaction.add(R.id.fragment, listFragment, TYPE_LIST_TAG);
} else {
if (!TextUtils.equals(search, TYPE_LIST_TAG)) {
RxBus.getInstance().post(ApiConfig.BUS, search);
}
transaction.show(listFragment);
}
}
transaction.commit();
}
示例10: freshUI
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void freshUI(){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment fragment = fragmentManager.findFragmentByTag(FreshNewsPostsFragment.TAG);
if(fragment == null){
fragment = new FreshNewsPostsFragment();
fragmentTransaction.add(R.id.container,fragment,FreshNewsPostsFragment.TAG);
}else{
fragmentTransaction.attach(fragment);
}
fragmentTransaction.commit();
}
示例11: showTipDialog
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showTipDialog(String code, String msg, PayTipsDialogFragment.OnDialogConfirmClickCallback callback) {
PayTipsDialogFragment dialog = PayTipsDialogFragment.newInstance(code, msg);
dialog.setCallback(callback);
if (getActivity() != null) {
FragmentTransaction ft = getMyFragmentManager(getActivity()).beginTransaction();
ft.add(dialog, RPConstant.RP_TIP_DIALOG_TAG);
ft.commitAllowingStateLoss();
}
}
示例12: addFragmentToActivity
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* The {@code fragment} is added to the container view with id {@code frameId}. The operation is
* performed by the {@code fragmentManager}.
*
*/
public static void addFragmentToActivity (@NonNull FragmentManager fragmentManager,
@NonNull Fragment fragment, int frameId) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(frameId, fragment);
transaction.commit();
}
示例13: changeFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* Shows fragment at position and detaches previous fragment if exists. If fragment is found in
* fragment manager, it is reattached else added.
*
* @param position
* @return fragment at position
*/
public Fragment changeFragment(int position) {
String tag = makeFragmentName(container.getId(), getItemId(position));
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
/*
If fragment manager doesn't have an instance of the fragment, get an instance
and add it to the transaction. Else, attach the instance to transaction.
*/
Fragment fragment = mFragmentManager.findFragmentByTag(tag);
if (fragment == null) {
fragment = getItem(position);
fragmentTransaction.add(container.getId(), fragment, tag);
} else {
fragmentTransaction.attach(fragment);
}
// Detach existing primary fragment
Fragment curFrag = mFragmentManager.getPrimaryNavigationFragment();
if (curFrag != null) {
fragmentTransaction.detach(curFrag);
}
// Set fragment as primary navigator for child manager back stack to be handled by system
fragmentTransaction.setPrimaryNavigationFragment(fragment);
fragmentTransaction.setReorderingAllowed(true);
fragmentTransaction.commitNowAllowingStateLoss();
return fragment;
}
示例14: switchFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void switchFragment(int lastIndex, int index) {
FragmentTransaction transaction = mFragmentManager.beginTransaction();
transaction.hide(mRxFragments[lastIndex]);
if (!mRxFragments[index].isAdded()) {
transaction.add(R.id.container, mRxFragments[index]);
}
transaction.show(mRxFragments[index]).commitAllowingStateLoss();
}
示例15: switchPanelFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void switchPanelFragment(BaseEditFragment baseEditFragment) {
if (baseEditFragment != mMainMenuFragment && baseEditFragment != mHollowFragment) {
undoButton.setVisibility(View.GONE);
}
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.remove(mCurrentPanelFragment);
fragmentTransaction.add(R.id.edit_panel_container, baseEditFragment);
mCurrentPanelFragment = baseEditFragment;
fragmentTransaction.commit();
}