本文整理汇总了Java中android.app.FragmentTransaction类的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction类的具体用法?Java FragmentTransaction怎么用?Java FragmentTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FragmentTransaction类属于android.app包,在下文中一共展示了FragmentTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initMap
import android.app.FragmentTransaction; //导入依赖的package包/类
private void initMap() {
PlaceAutocompleteFragment autocompleteFragment = new PlaceAutocompleteFragment();
CustomMapFragment mapFragment = new CustomMapFragment();
autocompleteFragment.setOnPlaceSelectedListener(this);
mapFragment.setParent(mBinding.scroll);
mapFragment.getMapAsync(this);
FragmentManager manager = getActivity().getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.place_autocomplete_fragment, autocompleteFragment);
transaction.add(R.id.google_map_fragment, mapFragment);
transaction.commit();
mMarkerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
mCircleOptions = new CircleOptions().fillColor(Color.argb(97, 93, 185, 139)).strokeColor(Color.argb(200, 93, 185, 139));
}
示例2: showDialog
import android.app.FragmentTransaction; //导入依赖的package包/类
public void showDialog(Bundle bundle) {
final Activity activity = (Activity) context;
FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
Fragment prev = activity.getFragmentManager().findFragmentByTag(fragmentTag);
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
newFragment = MyDialogFragment.newInstance(bundle);
newFragment.setList(list);
newFragment.setContext(context);
newFragment.setListener(listener);
newFragment.show(ft, fragmentTag);
}
示例3: onNavigationItemSelected
import android.app.FragmentTransaction; //导入依赖的package包/类
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.content, ProjectFragment.newInstance()); // newInstance() is a static factory method.
transaction.commit();
return true;
case R.id.navigation_dashboard:
FragmentManager newsManager = getFragmentManager();
FragmentTransaction transaction1 = newsManager.beginTransaction();
transaction1.replace(R.id.content, OrgFragment.newInstance()); // newInstance() is a static factory method.
transaction1.commit();
return true;
case R.id.navigation_notifications:
FragmentManager projectManager = getFragmentManager();
FragmentTransaction transaction2 = projectManager.beginTransaction();
transaction2.replace(R.id.content, MapFragment.newInstance()); // newInstance() is a static factory method.
transaction2.commit();
return true;
}
return false;
}
示例4: onNavigationItemSelected
import android.app.FragmentTransaction; //导入依赖的package包/类
/**
* Metodo encargado de la navegacion. Usa item.getTitle para manejar el caso de intentar
* navegar hacia la tab en la que ya estamos
* @param item
* @return true si se marca la tab, false si no
*/
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment newFragment = null;
if(!(tabActualTitle == item.getTitle())){
tabActualTitle = item.getTitle();
switch (item.getItemId()) {
case R.id.action_sofa:
newFragment = Sofa.newInstance();
break;
case R.id.action_torneo:
newFragment = Torneo.newInstance();
break;
case R.id.action_mapas:
newFragment = Mapas.newInstance();
break;
}
FragmentTransaction transaction = context.getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment, newFragment);
transaction.addToBackStack(null);
transaction.commit();
return true;
}else{
return false;
}
}
示例5: showDetails
import android.app.FragmentTransaction; //导入依赖的package包/类
/**
* Hide list, show details and instruct the details view to show the selected book.
*/
@Override
public void showDetails(Book book, Drawable thumb) {
final FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
BookDetailsFragment details = (BookDetailsFragment) fragmentManager.findFragmentById(R.id.book_details);
if (book != null) {
// If null passed, we only configure fragment transaction here.
details.showDetails(book, thumb);
}
ft.show(details);
ft.hide(fragmentManager.findFragmentById(R.id.book_list));
ft.addToBackStack("details"); // Use the back button to return to the search list view.
ft.commit();
}
示例6: removeFragment
import android.app.FragmentTransaction; //导入依赖的package包/类
public static void removeFragment(FragmentManager fragmentManager, int containViewId)
{
if(fragmentManager != null) {
Fragment fragment = fragmentManager.findFragmentById(containViewId);
if (fragment != null)
{
fragments.remove(fragment);
// TODO: Remove from backStackKeys
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.remove(fragment);
transaction.commitAllowingStateLoss();
}
}
else {
Log.e("FragmentHelper", "Fragment Manager = null");
}
}
示例7: hidePreFragment
import android.app.FragmentTransaction; //导入依赖的package包/类
private void hidePreFragment(FragmentTransaction transaction) {
Log.d(TAG, "hidePreFragment: mCurrentPageTag = "+mCurrentPageTag);
switch (mCurrentPageTag) {
case HOME_PAGE_TAG:
transaction.hide(mHomeFragment);
mHomeBtn.setTextColor(textColor);
break;
case EXPLORE_PAGE_TAG:
transaction.hide(mExploreFragment);
mExploreBtn.setTextColor(textColor);
break;
case MINE_PAGE_TAG:
transaction.hide(mMineFragment);
mMineBtn.setTextColor(textColor);
break;
}
}
示例8: onCreate
import android.app.FragmentTransaction; //导入依赖的package包/类
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_question);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
QuestionActivityFragment mainActivityFragment =
(QuestionActivityFragment) getFragmentManager().findFragmentById(R.id.content_question);
if (mainActivityFragment == null) {
mainActivityFragment = QuestionActivityFragment.newInstance();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.content_question, mainActivityFragment);
transaction.commit();
}
RequestFactory requestFactory = new RequestFactory();
TriviaSharedPreferences triviaSharedPreferences = new TriviaSharedPreferences(
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
int amount = getIntent().getIntExtra(AMOUNT, DEFAULT_AMOUNT_OF_QUESTIONS);
String categoryId = getIntent().getStringExtra(CATEGORY_ID);
String difficulty = getIntent().getStringExtra(DIFFICULTY);
String questionType = getIntent().getStringExtra(GAME_TYPE);
new QuestionPresenter(mainActivityFragment, requestFactory, triviaSharedPreferences, amount,
categoryId, difficulty, questionType);
}
示例9: reloadFragment
import android.app.FragmentTransaction; //导入依赖的package包/类
public static void reloadFragment(FragmentManager fragmentManager, Fragment fragment) {
if (fragment != null){
FragmentTransaction ft = fragmentManager.beginTransaction();
// ft.setTransition(-1);
// ft.replace(containViewId, fragment);
ft.detach(fragment);
ft.attach(fragment);
ft.commitAllowingStateLoss();
}
}
示例10: goToRegister
import android.app.FragmentTransaction; //导入依赖的package包/类
private void goToRegister(){
FragmentTransaction ft = getFragmentManager().beginTransaction();
RegisterFragment fragment = new RegisterFragment();
ft.replace(R.id.fragmentFrame,fragment,RegisterFragment.TAG);
ft.commit();
}
示例11: showUserFragment
import android.app.FragmentTransaction; //导入依赖的package包/类
private void showUserFragment(User user){
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment prev = getFragmentManager().findFragmentByTag(USER_FRAGMENT_LABEL);
if(prev != null){
ft.remove(prev);
}
ft.addToBackStack(null);
UserFragment newFragment = UserFragment.newInstance(user);
newFragment.show(ft, USER_FRAGMENT_LABEL);
}
示例12: changeFragment
import android.app.FragmentTransaction; //导入依赖的package包/类
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
/*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
if (newFragmentType.isRightOf(currentFragment)) {
transaction.setCustomAnimations(R.anim.slide_in_right_to_left,
R.anim.slide_out_right_to_left,
R.anim.slide_in_left_to_right,
R.anim.slide_out_left_to_right);
} else {
transaction.setCustomAnimations(R.anim.slide_in_left_to_right,
R.anim.slide_out_left_to_right,
R.anim.slide_in_right_to_left,
R.anim.slide_out_right_to_left);
}
}*/
if (newFragmentType != FragmentsAvailable.DIALER
&& newFragmentType != FragmentsAvailable.CONTACTS_LIST
&& newFragmentType != FragmentsAvailable.CHAT_LIST
&& newFragmentType != FragmentsAvailable.HISTORY_LIST) {
transaction.addToBackStack(newFragmentType.toString());
} else {
while (fm.getBackStackEntryCount() > 0) {
fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
}
transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
transaction.commitAllowingStateLoss();
fm.executePendingTransactions();
currentFragment = newFragmentType;
}
示例13: onCreate
import android.app.FragmentTransaction; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Check NightMode On/Off
mConfig = getSharedPreferences(getString(R.string.key_config), MODE_PRIVATE);
boolean isNightMode = mConfig.getBoolean(getString(R.string.key_is_night_mode), false);
if (isNightMode) {
setTheme(R.style.DarkTheme);
} else {
setTheme(R.style.LightTheme);
}
checkPermission();
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_new_create); //Binding Layout
initToolbar();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
mFragment = SettingFragment.newInstance();
transaction.add(R.id.setting_fragment, mFragment);
transaction.commit();
mRealm = Realm.getDefaultInstance(); // Initialize Realm
// Intent intent = getIntent();
// if (intent.getStringExtra("data") != null) {
// Bundle bundle = new Bundle();
// bundle.putString("data", intent.getStringExtra("data"));
// mFragment.setArguments(bundle);
// if (intent.getStringExtra(getString(R.string.key_title)) != null) {
// mFragment.setArguments(intent.getExtras());
// }
// }
}
示例14: detach
import android.app.FragmentTransaction; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void detach(Fragment fragment,
FragmentTransaction currTransaction) {
currTransaction.detach(fragment);
}
示例15: summitFragment
import android.app.FragmentTransaction; //导入依赖的package包/类
private void summitFragment(String mediaId) {
BrowserFragment fragment = getFragment();
if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) {
fragment = BrowserFragment.newInstance(mediaId);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.container, fragment, FRAGMENT_TAG);
// If this is not the top level media (root), we add it to the fragment back stack,
// so that actionbar toggle and Back will work appropriately:
if (mediaId != null) {
transaction.addToBackStack(null);
}
transaction.commit();
}
}