Here are the examples of the java api android.app.FragmentTransaction.add() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
79 Examples
19
Source : BaseDialogFragment.java
with MIT License
from usernameyangyan
with MIT License
from usernameyangyan
public int show(FragmentTransaction transaction, String tag) {
return transaction.add(this, tag).commitAllowingStateLoss();
}
18
Source : DispatcherActivityCallbackTest.java
with Apache License 2.0
from lulululbj
with Apache License 2.0
from lulululbj
@SuppressLint("CommitTransaction")
private void checkReportFragment(LifecycleDispatcher.DispatcherActivityCallback callback, Activity activity) {
android.app.FragmentManager fm = mock(android.app.FragmentManager.clreplaced);
FragmentTransaction transaction = mock(FragmentTransaction.clreplaced);
when(activity.getFragmentManager()).thenReturn(fm);
when(fm.beginTransaction()).thenReturn(transaction);
when(transaction.add(any(Fragment.clreplaced), anyString())).thenReturn(transaction);
callback.onActivityCreated(activity, mock(Bundle.clreplaced));
verify(activity).getFragmentManager();
verify(fm).beginTransaction();
verify(transaction).add(any(ReportFragment.clreplaced), anyString());
verify(transaction).commit();
}
17
Source : BaseActivity.java
with MIT License
from ZafraniTechLLC
with MIT License
from ZafraniTechLLC
public void showFragment(@NonNull final Fragment fragment, @IdRes final int contentView, @NonNull final String tag) {
final FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
final Fragment topFragment = getTopFragment();
if (topFragment == null) {
fragTransaction.add(contentView, fragment, tag);
} else {
fragTransaction.replace(contentView, fragment, tag);
}
fragTransaction.commit();
getFragmentManager().executePendingTransactions();
}
17
Source : ImagePickerFragment.java
with Apache License 2.0
from wurensen
with Apache License 2.0
from wurensen
/**
* 关联fragment
*
* @param activity 界面
* @param imagePicker 选择器
* @return 如果已经添加直接返回,否则创建并添加
*/
static ImagePickerFragment attach(Activity activity, ImagePicker imagePicker) {
FragmentManager fragmentManager = activity.getFragmentManager();
String tag = "ImagePickerFragment";
ImagePickerFragment fragment = (ImagePickerFragment) fragmentManager.findFragmentByTag(tag);
if (fragment == null) {
fragment = new ImagePickerFragment();
fragment.setRetainInstance(true);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(fragment, tag);
transaction.commitAllowingStateLoss();
}
fragment.mImagePicker = imagePicker;
return fragment;
}
17
Source : BaseActivity.java
with Apache License 2.0
from ukevgen
with Apache License 2.0
from ukevgen
protected void addFragment(int containerViewId, Fragment fragment) {
final FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction();
fragmentTransaction.add(containerViewId, fragment);
fragmentTransaction.commit();
}
17
Source : ActivityUtils.java
with MIT License
from stanmots
with MIT License
from stanmots
/**
* The {@code fragment} is added to the container view with id {@code frameId}. The operation is
* performed by the {@code fragmentManager}.
*
* @param fragmentManager {@link FragmentManager} replacedociated with {@link android.app.Activity}.
* @param fragment {@link Fragment} to add.
* @param tag A string identifying the fragment.
*/
public static void addFragmentToActivity(@NonNull final FragmentManager fragmentManager, @NonNull final Fragment fragment, @NonNull final String tag) {
checkNotNull(fragmentManager, "fragmentManager must not be null!");
checkNotNull(fragment, "fragment must not be null!");
checkNotNull(tag, "tag must not be null!");
checkArgument(!tag.isEmpty(), "tag string must not be empty!");
removeFragment(fragmentManager, tag);
final FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(fragment, tag);
transaction.commitAllowingStateLoss();
}
17
Source : FeedBackActivity.java
with Apache License 2.0
from JackChan1999
with Apache License 2.0
from JackChan1999
private void initUI() {
this.mInputMethodManager = (InputMethodManager) getSystemService("input_method");
getWindow().setSoftInputMode(16);
this.mFeedBackAnimFragment = new FeedBackAnimFragment();
this.mScrollView = (ScrollView) findViewById(R.id.feedback_scroll_view);
this.mNumberTextView = (TextView) findViewById(R.id.text_number);
this.mBackImageView = (ImageView) findViewById(R.id.back_my);
this.mQQFansTextView = (TextView) findViewById(R.id.letv_fans_qq);
this.mCommunityTextView = (TextView) findViewById(R.id.le_community);
this.mFeedBackEditText = (EditText) findViewById(R.id.feedback_content);
this.mSubmitTextView = (TextView) findViewById(R.id.feedback_submit);
this.mUserContactEditText = (EditText) findViewById(R.id.feedback_contact);
this.mImageParentLayout = (LinearLayout) findViewById(R.id.imageParent);
this.mImageDefaultLayout = (LinearLayout) findViewById(R.id.feedback_image_default);
this.mAddImageTextView = (TextView) findViewById(R.id.add_image_text);
this.mSuccessLayout = (LinearLayout) findViewById(R.id.submit_success);
this.mBackBtn = (Button) findViewById(R.id.back_to_main);
this.mFeedBackBodyLayout = (LinearLayout) findViewById(R.id.feedback_body);
this.mBackImageView.setOnClickListener(this);
this.mBackBtn.setOnClickListener(this);
this.mAddImageTextView.setOnClickListener(this);
this.mImageDefaultLayout.setOnClickListener(this);
this.mUserContactEditText.setOnClickListener(this);
this.mUserContactEditText.setOnTouchListener(this);
this.mSubmitTextView.setOnClickListener(this);
this.mCommunityTextView.setOnClickListener(this);
this.mFeedBackEditText.setOnClickListener(this);
this.mFeedBackEditText.addTextChangedListener(this);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.feedback_bottom, this.mFeedBackAnimFragment);
fragmentTransaction.commit();
initData();
}
17
Source : ContentActivity.java
with Apache License 2.0
from huangxin388
with Apache License 2.0
from huangxin388
private void startView() {
int start = 0;
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
start = getIntent().getIntExtra("start_view", 0);
switch(start) {
case 2:
transaction.add(R.id.content_layout, new VariationFragment());
break;
case 3:
transaction.add(R.id.content_layout, new JisawFragment());
break;
case 4:
transaction.add(R.id.content_layout, new ColorChangeFragment());
break;
case 1:
default:
transaction.add(R.id.content_layout, new CameraFragment());
}
transaction.commit();
}
17
Source : ScopeHolderFragment.java
with Apache License 2.0
from bytedance
with Apache License 2.0
from bytedance
@NonNull
public static ScopeHolderFragment install(@NonNull Activity activity, @NonNull String tag, boolean forceCreate, boolean immediate) {
String fragmentTag = tag + "_" + TAG;
FragmentManager fragmentManager = activity.getFragmentManager();
ScopeHolderFragment holderFragment = (ScopeHolderFragment) fragmentManager.findFragmentByTag(fragmentTag);
if (holderFragment != null && forceCreate) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.remove(holderFragment);
Utility.commitFragment(fragmentManager, transaction, immediate);
holderFragment = null;
}
if (holderFragment == null) {
holderFragment = ScopeHolderFragment.newInstance();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(holderFragment, fragmentTag);
Utility.commitFragment(fragmentManager, transaction, immediate);
}
return holderFragment;
}
17
Source : LeanbackSettingsFragment.java
with Apache License 2.0
from androidx
with Apache License 2.0
from androidx
/**
* Displays a fragment to the user, temporarily replacing the contents of this fragment.
*
* @param fragment Fragment instance to be added.
*/
public void startImmersiveFragment(@NonNull Fragment fragment) {
final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
final Fragment preferenceFragment = getChildFragmentManager().findFragmentByTag(PREFERENCE_FRAGMENT_TAG);
if (preferenceFragment != null && !preferenceFragment.isHidden()) {
if (Build.VERSION.SDK_INT < 23) {
// b/22631964
transaction.add(R.id.settings_preference_fragment_container, new DummyFragment());
}
transaction.remove(preferenceFragment);
}
transaction.add(R.id.settings_dialog_container, fragment).addToBackStack(null).commit();
}
16
Source : MainActivity.java
with MIT License
from zhusheng
with MIT License
from zhusheng
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 添加主容器
FragmentTransaction transaction = getFragmentManager().beginTransaction();
navigationFragment = new NavigationFragment();
transaction.add(R.id.main_frame, navigationFragment);
transaction.commit();
}
16
Source : DeleteActionActivity.java
with MIT License
from rrishabhj
with MIT License
from rrishabhj
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delete_action);
if (savedInstanceState == null) {
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.container, DeleteActionFragment.newInstance(), FRAGMENT_TAG_DELETE_ACTION);
ft.commit();
}
}
16
Source : WrapFragmentActivity.java
with Apache License 2.0
from luckybilly
with Apache License 2.0
from luckybilly
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wrap_fragment);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.frame_container, new WrapRootViewFragment());
transaction.commit();
}
16
Source : GoogleSignInFragment.java
with MIT License
from loukaspd
with MIT License
from loukaspd
public static void SignIn(Activity unityActivity) {
if (WebClientId == null || WebClientId.length() == 0) {
return;
}
FragmentTransaction trans = unityActivity.getFragmentManager().beginTransaction();
trans.add(new GoogleSignInFragment(), Tag);
trans.commitAllowingStateLoss();
}
16
Source : FragmentDialogOrActivity.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_dialog_or_activity);
if (savedInstanceState == null) {
// First-time init; create fragment to embed in activity.
// BEGIN_INCLUDE(embed)
FragmentTransaction ft = getFragmentManager().beginTransaction();
DialogFragment newFragment = MyDialogFragment.newInstance();
ft.add(R.id.embedded, newFragment);
ft.commit();
// END_INCLUDE(embed)
}
// Watch for button clicks.
Button button = (Button) findViewById(R.id.show_dialog);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog();
}
});
}
16
Source : LittleWindow.java
with GNU General Public License v3.0
from hh-in-zhuzhou
with GNU General Public License v3.0
from hh-in-zhuzhou
public void show(FragmentManager manager) {
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, getTagName());
ft.addToBackStack(getTagName());
ft.commit();
}
16
Source : GlassCallActivity.java
with Apache License 2.0
from googlesamples
with Apache License 2.0
from googlesamples
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
callFragment = new GlreplacedCallFragment();
callFragment.setArguments(getIntent().getExtras());
hudFragment = new GlreplacedHudFragment();
hudFragment.setArguments(getIntent().getExtras());
gestureDetector = new GlreplacedGestureDetector(this, this);
callFragment.setArguments(getIntent().getExtras());
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.hud_fragment_container, hudFragment);
ft.add(R.id.call_fragment_container, callFragment);
ft.commit();
}
16
Source : PlaybackActivity.java
with Apache License 2.0
from googlearchive
with Apache License 2.0
from googlearchive
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
mClip = getIntent().getParcelableExtra(EXTRA_CLIP);
mProgress = getIntent().getLongExtra(EXTRA_PROGRESS, -1);
VideoFragment videoFragment = VideoFragment.newInstance(mClip, mProgress);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(android.R.id.content, videoFragment);
fragmentTransaction.commit();
}
}
16
Source : ActivityUtils.java
with Apache License 2.0
from gengqifu
with Apache License 2.0
from gengqifu
/**
* 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) {
checkNotNull(fragmentManager);
checkNotNull(fragment);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(frameId, fragment);
transaction.commit();
}
16
Source : HomeActivity.java
with Apache License 2.0
from FreeSunny
with Apache License 2.0
from FreeSunny
private void showFragment(int tabIndex, FragmentTransaction transaction) {
Fragment fragment = getFragmentByIndex(tabIndex);
if (fragment == null) {
switch(tabIndex) {
case 0:
fragment = new DialFragment();
break;
case 1:
fragment = new VerticalGridFragment();
break;
case 2:
fragment = new VerticalGridFragment1();
break;
}
transaction.add(R.id.tab_container, fragment, TAGS[tabIndex]);
// transaction.addToBackStack(TAGS[tabIndex]);
} else {
transaction.show(fragment);
}
}
16
Source : CategoriesActivity.java
with Apache License 2.0
from claudiodegio
with Apache License 2.0
from claudiodegio
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
mFragment = TableViewerFragment.newInstance("db4", "CATEGORY");
mFragment.setOnItemClicked(this);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.flFragment, mFragment, "TAG").commit();
}
16
Source : ArticlesActivity.java
with Apache License 2.0
from claudiodegio
with Apache License 2.0
from claudiodegio
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
mFragment = TableViewerFragment.newInstance("db4", "article");
mFragment.setOnItemClicked(this);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.flFragment, mFragment, "TAG").commit();
}
16
Source : MainDb3Activity.java
with Apache License 2.0
from claudiodegio
with Apache License 2.0
from claudiodegio
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_main_db3);
super.onCreate(savedInstanceState);
mFragment = TableViewerFragment.newInstance("db3", "name");
mFragment.setOnItemClicked(this);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.flFragment, mFragment, "TAG").commit();
}
16
Source : NamesActivity.java
with Apache License 2.0
from claudiodegio
with Apache License 2.0
from claudiodegio
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
mFragment = TableViewerFragment.newInstance("db2", "name");
mFragment.setOnItemClicked(this);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.flFragment, mFragment, "TAG").commit();
}
16
Source : CategoriesActivity.java
with Apache License 2.0
from claudiodegio
with Apache License 2.0
from claudiodegio
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
mFragment = TableViewerFragment.newInstance("db2", "CATEGORY");
mFragment.setOnItemClicked(this);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.flFragment, mFragment, "TAG").commit();
}
16
Source : MainDb1Activity.java
with Apache License 2.0
from claudiodegio
with Apache License 2.0
from claudiodegio
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_main_db1);
super.onCreate(savedInstanceState);
mFragment = TableViewerFragment.newInstance("db1", "name");
mFragment.setOnItemClicked(this);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.flFragment, mFragment, "TAG").commit();
}
16
Source : DetailsFragment.java
with Apache License 2.0
from androidx
with Apache License 2.0
from androidx
/**
* This method asks DetailsFragmentBackgroundController to add a fragment for rendering video.
* In case the fragment is already there, it will return the existing one. The method must be
* called after calling super.onCreate(). App usually does not call this method directly.
*
* @return Fragment the added or restored fragment responsible for rendering video.
* @see DetailsFragmentBackgroundController#onCreateVideoFragment()
*/
final Fragment findOrCreateVideoFragment() {
if (mVideoFragment != null) {
return mVideoFragment;
}
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.video_surface_container);
if (fragment == null && mDetailsBackgroundController != null) {
FragmentTransaction ft2 = getChildFragmentManager().beginTransaction();
ft2.add(androidx.leanback.R.id.video_surface_container, fragment = mDetailsBackgroundController.onCreateVideoFragment());
ft2.commit();
if (mPendingFocusOnVideo) {
// wait next cycle for Fragment view created so we can focus on it.
// This is a bit hack eventually we will do commitNow() which get view immediately.
getView().post(new Runnable() {
@Override
public void run() {
if (getView() != null) {
switchToVideo();
}
mPendingFocusOnVideo = false;
}
});
}
}
mVideoFragment = fragment;
return mVideoFragment;
}
16
Source : SmsStorageLowWarningActivity.java
with Apache License 2.0
from alperali
with Apache License 2.0
from alperali
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentTransaction ft = getFragmentManager().beginTransaction();
SmsStorageLowWarningFragment fragment = SmsStorageLowWarningFragment.newInstance();
ft.add(fragment, null);
ft.commit();
}
15
Source : ActivityTwo.java
with Apache License 2.0
from Zane96
with Apache License 2.0
from Zane96
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
Toast.makeText(this, data, Toast.LENGTH_SHORT).show();
TextView mText = (TextView) findViewById(R.id.text_person);
mText.setText("age: " + person.getAge() + " name: " + person.getName());
findViewById(R.id.button_two).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EasyRouter.setResult(ActivityTwo.this, 0, new MessageBuilder().addParam("result_two", "data from two", String.clreplaced).build());
ActivityTwo.this.finish();
}
});
FragmentTransaction transaction = getFragmentManager().beginTransaction();
FragmentTwo fragmentTwo = new FragmentTwo();
fragmentTwo.setListener(new FragmentTwo.OnResultListener() {
@Override
public void onResult() {
Toast.makeText(ActivityTwo.this, result, Toast.LENGTH_SHORT).show();
}
});
transaction.add(R.id.fragment_activity_two, fragmentTwo).commit();
}
15
Source : MainActivity.java
with MIT License
from yuchenfw
with MIT License
from yuchenfw
public void initView() {
mGvPage = (GridView) findViewById(R.id.pageView);
int[] images = { R.drawable.b_newhome_tabbar_night, R.drawable.b_newdiscover_tabbar_night, R.drawable.b_newcare_tabbar_night, R.drawable.b_newmine_tabbar_night };
int[] newImages = { R.drawable.b_newhome_tabbar_press, R.drawable.b_newdiscover_tabbar_press, R.drawable.b_newcare_tabbar_press, R.drawable.b_newmine_tabbar_press };
String[] replacedles = { "首页", "视频", "关注", "我的" };
final GridViewAdapter adapter = new GridViewAdapter(MainActivity.this, images, replacedles, newImages);
mGvPage.setAdapter(adapter);
mGvPage.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
System.out.println("点击的位置是" + i);
adapter.setSelectPosition(i);
adapter.notifyDataSetChanged();
FragmentTransaction ft = getFragmentManager().beginTransaction();
switch(i) {
case 0:
ft.replace(R.id.content_view, HomeFragment.newInstance(0)).commit();
break;
case 1:
ft.replace(R.id.content_view, HomeFragment.newInstance(1)).commit();
break;
}
}
});
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.content_view, new HomeFragment()).commit();
adapter.setSelectPosition(0);
}
15
Source : ProfileActivity.java
with Apache License 2.0
from sahuadarsh0
with Apache License 2.0
from sahuadarsh0
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
if (savedInstanceState == null) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.fragment_container, new MainFragment(ProfileActivity.this), "MainFragment");
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
fragmentTransaction.commit();
}
}
15
Source : RxResultHoldFragment.java
with Apache License 2.0
from jjerry
with Apache License 2.0
from jjerry
public static RxResultHoldFragment getHoldFragment(FragmentManager fragmentManager) {
RxResultHoldFragment holdFragment = new RxResultHoldFragment();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(holdFragment, RxResultHoldFragment.TAG);
transaction.commit();
return holdFragment;
}
15
Source : FragmentCustomAnimations.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_stack);
// Watch for button clicks.
Button button = (Button) findViewById(R.id.new_fragment);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
addFragmentToStack();
}
});
if (savedInstanceState == null) {
// Do first time initialization -- add initial fragment.
Fragment newFragment = CountingFragment.newInstance(mStackLevel);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.simple_fragment, newFragment).commit();
} else {
mStackLevel = savedInstanceState.getInt("level");
}
}
15
Source : FragmentArguments.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
// BEGIN_INCLUDE(create)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_arguments);
if (savedInstanceState == null) {
// First-time init; create fragment to embed in activity.
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment newFragment = MyFragment.newInstance("From Arguments");
ft.add(R.id.created, newFragment);
ft.commit();
}
}
15
Source : MainActivity.java
with Apache License 2.0
from duwurensheng010
with Apache License 2.0
from duwurensheng010
private void showChangelog() {
FragmentTransaction changelogTx = getFragmentManager().beginTransaction();
WebViewDialogFragment changelogFragment = WebViewDialogFragment.newInstance(R.string.whats_new, "file:///android_replacedet/changelog/changelog.html");
changelogTx.add(changelogFragment, "changelog");
changelogTx.commit();
}
15
Source : ActivityUtils.java
with Apache License 2.0
from DrownCoder
with Apache License 2.0
from DrownCoder
/**
* The {@code fragment} is added to the container view with id {@code frameId}. The operation is
* performed by the {@code fragmentManager}.
*/
@SuppressLint("RestrictedApi")
public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId) {
checkNotNull(fragmentManager);
checkNotNull(fragment);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(frameId, fragment);
transaction.commit();
}
15
Source : VideoActivityWithDetailedCard.java
with Apache License 2.0
from androidx
with Apache License 2.0
from androidx
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_activity_detailed_card);
if (savedInstanceState == null) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.videoFragment, new VideoConsumptionWithDetailCardFragment(), VideoConsumptionWithDetailCardFragment.TAG);
ft.commit();
}
}
15
Source : LeanbackSettingsFragment.java
with Apache License 2.0
from androidx
with Apache License 2.0
from androidx
/**
* Displays a preference fragment to the user. This method can also be used to display
* list-style fragments on top of the stack of preference fragments.
*
* @param fragment Fragment instance to be added.
*/
public void startPreferenceFragment(@NonNull Fragment fragment) {
final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
final Fragment prevFragment = getChildFragmentManager().findFragmentByTag(PREFERENCE_FRAGMENT_TAG);
if (prevFragment != null) {
transaction.addToBackStack(null).replace(R.id.settings_preference_fragment_container, fragment, PREFERENCE_FRAGMENT_TAG);
} else {
transaction.add(R.id.settings_preference_fragment_container, fragment, PREFERENCE_FRAGMENT_TAG);
}
transaction.commit();
}
15
Source : VideoExampleWithExoPlayerActivity.java
with Apache License 2.0
from android
with Apache License 2.0
from android
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_example);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.videoFragment, new VideoConsumptionExampleWithExoPlayerFragment(), VideoConsumptionExampleWithExoPlayerFragment.TAG);
ft.commit();
}
15
Source : VideoExampleActivity.java
with Apache License 2.0
from android
with Apache License 2.0
from android
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_example);
if (savedInstanceState == null) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.videoFragment, new VideoConsumptionExampleFragment(), VideoConsumptionExampleFragment.TAG);
ft.commit();
}
}
14
Source : NavigationFragment.java
with MIT License
from zhusheng
with MIT License
from zhusheng
/**
* 设置Tab选中
* @param id
*/
public void setTabSelection(int id) {
// 重置所有tabItem状态
tabItemHomeBtn.setImageResource(R.drawable.tab_item_home_focus);
tabItemCategoryBtn.setImageResource(R.drawable.tab_item_category_focus);
tabItemCartBtn.setImageResource(R.drawable.tab_item_cart_focus);
tabItemPersonalBtn.setImageResource(R.drawable.tab_item_personal_focus);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
// 隐藏所有Fragment
if (homeFragment != null)
fragmentTransaction.hide(homeFragment);
if (categoryFragment != null)
fragmentTransaction.hide(categoryFragment);
if (cartFragment != null)
fragmentTransaction.hide(cartFragment);
if (personFragment != null)
fragmentTransaction.hide(personFragment);
// 根据tabItem的id来执行不同的操作
switch(id) {
case R.id.tab_item_home:
tabItemHomeBtn.setImageResource(R.drawable.tab_item_home_normal);
if (homeFragment == null) {
homeFragment = new HomeFragment();
fragmentTransaction.add(R.id.content, homeFragment);
} else {
fragmentTransaction.show(homeFragment);
}
break;
case R.id.tab_item_category:
tabItemCategoryBtn.setImageResource(R.drawable.tab_item_category_normal);
if (categoryFragment == null) {
categoryFragment = new CategoryFragment();
fragmentTransaction.add(R.id.content, categoryFragment);
} else {
fragmentTransaction.show(categoryFragment);
}
break;
case R.id.tab_item_cart:
tabItemCartBtn.setImageResource(R.drawable.tab_item_cart_normal);
if (cartFragment == null) {
cartFragment = new CartFragment();
fragmentTransaction.add(R.id.content, cartFragment);
} else {
fragmentTransaction.show(cartFragment);
}
break;
case R.id.tab_item_personal:
tabItemPersonalBtn.setImageResource(R.drawable.tab_item_personal_normal);
if (personFragment == null) {
personFragment = new PersonFragment();
fragmentTransaction.add(R.id.content, personFragment);
} else {
fragmentTransaction.show(personFragment);
}
break;
}
fragmentTransaction.commit();
currentId = id;
}
14
Source : LoginActivity.java
with MIT License
from zhusheng
with MIT License
from zhusheng
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Log.i(TAG, "onCreate");
BaseFragment baseFragment = new BaseFragment();
// Fragment管理类
FragmentManager manager = getFragmentManager();
// 事务
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.fragment_content, baseFragment);
// 一定要记得提交
transaction.commit();
}
14
Source : MainActivity.java
with MIT License
from zhusheng
with MIT License
from zhusheng
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG, "onCreate");
// 新建Fragment一个对象
BaseFragment baseFragment = new BaseFragment();
// 新建一个FragmentManager
FragmentManager fragmentManager = getFragmentManager();
// 新建一个FragmentTransaction对象
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
// 添加Fragment到容器,并提交事务
fragmentTransaction.add(R.id.fragment_content, baseFragment);
fragmentTransaction.commit();
}
14
Source : PreferenceActivity.java
with GNU General Public License v3.0
from tianyuan168326
with GNU General Public License v3.0
from tianyuan168326
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preference, "NONo个性化");
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
NONoPreferenceFragment prefFragment = new NONoPreferenceFragment();
transaction.add(R.id.prefFragment, prefFragment);
transaction.commit();
}
14
Source : FragmentStackFragment.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// Do first time initialization -- add initial fragment.
Fragment newFragment = FragmentStack.CountingFragment.newInstance(mStackLevel);
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.add(R.id.simple_fragment, newFragment).commit();
} else {
mStackLevel = savedInstanceState.getInt("level");
}
}
14
Source : FragmentStack.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_stack);
// Watch for button clicks.
Button button = (Button) findViewById(R.id.new_fragment);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
addFragmentToStack();
}
});
button = (Button) findViewById(R.id.delete_fragment);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
getFragmentManager().popBackStack();
}
});
if (savedInstanceState == null) {
// Do first time initialization -- add initial fragment.
Fragment newFragment = CountingFragment.newInstance(mStackLevel);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.simple_fragment, newFragment).commit();
} else {
mStackLevel = savedInstanceState.getInt("level");
}
}
14
Source : FragmentReceiveResult.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
FrameLayout frame = new FrameLayout(this);
frame.setId(R.id.simple_fragment);
setContentView(frame, lp);
if (savedInstanceState == null) {
// Do first time initialization -- add fragment.
Fragment newFragment = new ReceiveResultFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.simple_fragment, newFragment).commit();
}
}
14
Source : FragmentMenu.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_menu);
// Make sure the two menu fragments are created.
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
mFragment1 = fm.findFragmentByTag("f1");
if (mFragment1 == null) {
mFragment1 = new MenuFragment();
ft.add(mFragment1, "f1");
}
mFragment2 = fm.findFragmentByTag("f2");
if (mFragment2 == null) {
mFragment2 = new Menu2Fragment();
ft.add(mFragment2, "f2");
}
ft.commit();
// Watch check box clicks.
mCheckBox1 = (CheckBox) findViewById(R.id.menu1);
mCheckBox1.setOnClickListener(mClickListener);
mCheckBox2 = (CheckBox) findViewById(R.id.menu2);
mCheckBox2.setOnClickListener(mClickListener);
// Make sure fragments start out with correct visibility.
updateFragmentVisibility();
}
14
Source : FragmentArgumentsFragment.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// First-time init; create fragment to embed in activity.
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
Fragment newFragment = FragmentArguments.MyFragment.newInstance("From Arguments 1");
ft.add(R.id.created1, newFragment);
newFragment = FragmentArguments.MyFragment.newInstance("From Arguments 2");
ft.add(R.id.created2, newFragment);
ft.commit();
}
}
14
Source : ActionSheet.java
with GNU General Public License v3.0
from hh-in-zhuzhou
with GNU General Public License v3.0
from hh-in-zhuzhou
public void show(FragmentManager manager, String tag) {
if (!mDismissed) {
return;
}
mDismissed = false;
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, tag);
ft.addToBackStack("actionSheet");
ft.commit();
}
See More Examples