本文整理匯總了Java中android.app.FragmentTransaction.add方法的典型用法代碼示例。如果您正苦於以下問題:Java FragmentTransaction.add方法的具體用法?Java FragmentTransaction.add怎麽用?Java FragmentTransaction.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.add方法的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: onCreate
import android.app.FragmentTransaction; //導入方法依賴的package包/類
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
MainActivityFragment mainActivityFragment =
(MainActivityFragment) getFragmentManager().findFragmentById(R.id.content_main);
if (mainActivityFragment == null) {
mainActivityFragment = MainActivityFragment.newInstance();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.content_main, mainActivityFragment);
transaction.commit();
}
RequestFactory requestFactory = new RequestFactory();
TriviaSharedPreferences triviaSharedPreferences = new TriviaSharedPreferences(
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
new MainPresenter(mainActivityFragment, requestFactory, triviaSharedPreferences);
}
示例3: showDialogFragment
import android.app.FragmentTransaction; //導入方法依賴的package包/類
private void showDialogFragment(int dialogId, String customMessage) {
if (mDestroyed) {
return;
}
mProgressBar.setIndeterminate(false);
DialogFragment fragment;
switch (dialogId) {
case R.id.dialog_account_setup_error: {
fragment = ConfirmationDialogFragment.newInstance(dialogId,
getString(R.string.account_setup_failed_dlg_title),
customMessage,
getString(R.string.account_setup_failed_dlg_edit_details_action),
getString(R.string.account_setup_failed_dlg_continue_action)
);
break;
}
default: {
throw new RuntimeException("Called showDialog(int) with unknown dialog id.");
}
}
FragmentTransaction ta = getFragmentManager().beginTransaction();
ta.add(fragment, getDialogTag(dialogId));
ta.commitAllowingStateLoss();
// TODO: commitAllowingStateLoss() is used to prevent https://code.google.com/p/android/issues/detail?id=23761
// but is a bad...
//fragment.show(ta, getDialogTag(dialogId));
}
示例4: onCreate
import android.app.FragmentTransaction; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picker);
PickerViewModel viewModel = PickerViewModel.getInstance();
File internalDirectory = getFilesDir();
for (File f : internalDirectory.listFiles()) {
viewModel.addFile(f);
}
// Only add our fragments on first run of the activity
if (savedInstanceState == null) {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.list_fragment_container, new ListFragment());
DetailFragment df = new DetailFragment();
ft.add(R.id.detail_fragment_container, df);
ft.commit();
}
}
示例5: onTabSelected
import android.app.FragmentTransaction; //導入方法依賴的package包/類
/**
* @brief Method called when the tab is selected
* @param tab
* @param ft
* @details Method called when the tab is selected
*/
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// Check if the fragment is already initialized
mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);
mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
if (mFragment == null) {
// If not, instantiate and add it to the activity
mFragment = Fragment.instantiate(
mActivity, mClass.getName());
//mFragment.setProviderId(mTag); // id for event provider
setmTransaction(ft);
ft.add(android.R.id.content, mFragment, mTag);
} else {
// If it exists, simply attach it in order to show it
setmTransaction(ft);
ft.attach(mFragment);
}
}
示例6: onCreate
import android.app.FragmentTransaction; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!runFirst) return;
if (savedInstanceState == null) {
fileManagerFragment.create(this.getApplicationContext(), this);
waiterFragment.create();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
for (Fragment f : fragments.values()) {
fragmentTransaction.add(R.id.rootContainer, f);
fragmentTransaction.hide(f);
}
fragmentTransaction.commit();
showFragment("server_list");
sshServersSelector.setActionListener(this);
fileManagerFragment.setActionListener(this);
runFirst = false;
}
}
示例7: onCreate
import android.app.FragmentTransaction; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
mContentFragment = getCurrentFragment(this);
// If there's no fragment to use, we're done here.
if (mContentFragment == null) {
finish();
}
// Wire up the fragment
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
// 實現接口的fragment,直接強轉為fragment
fragmentTransaction.add(R.id.welcome_content, (Fragment) mContentFragment);
fragmentTransaction.commit();
LOGD(TAG, "Inside Create View.");
setupAnimation();
}
示例8: addFragment
import android.app.FragmentTransaction; //導入方法依賴的package包/類
/**
* 添加fragmnet進入
*
* @param containerViewId fragment添加的viewId
* @param fragment 具體的fragment
* @param tag fragment對應的tag
* @param addStack 是否添加到回退棧
*/
public void addFragment(@IdRes int containerViewId, Fragment fragment, String tag, boolean addStack) {
FragmentTransaction transaction = getTransaction();
/* if (addStack) {
//為true時才進行動畫
//1參數為進入動畫,4參數為出去動畫,中間2個好像無效
transaction.setCustomAnimations(R.anim.h_fragment_enter, R.anim.h_fragment_exit, R.anim.h_fragment_pop_enter, R.anim.h_fragment_pop_exit);
}*/
transaction.add(containerViewId, fragment, tag);
//看看是否添加到回退棧,全部交由實際控製,一般第一個fragment都不添加回退棧,會造成空白\
if (addStack)
transaction.addToBackStack(null);
transaction.commit();
List<Fragment> fragmentList = getFragmentList(containerViewId);
fragmentList.add(fragment);
mFragmentListMap.put(containerViewId, fragmentList);
}
示例9: 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);
}
示例10: openFragment
import android.app.FragmentTransaction; //導入方法依賴的package包/類
private void openFragment(Fragment fragment) {
this.fragment = fragment;
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.addParticipantContainer, fragment);
fragmentTransaction.commit();
addParticipantContainer.setVisibility(View.VISIBLE);
isFragmentOpen = true;
}
示例11: switchFragment
import android.app.FragmentTransaction; //導入方法依賴的package包/類
private void switchFragment(int index) {
if (index == mCurrentIndex) return;
Fragment fragment = mFragments.get(index);
FragmentTransaction transaction =
mFragmentManager
.beginTransaction()
.setCustomAnimations(R.animator.fragment_in, R.animator.fragment_out);
String indexString = String.valueOf(index);
Fragment targetFragment = mFragmentManager.findFragmentByTag(indexString);
if (mCurrentIndex != -1) {
// 不是首次啟動
transaction.hide(mFragments.get(mCurrentIndex));
}
if (targetFragment == null) {
// 之前沒有添加過
transaction.add(R.id.fl_content, fragment, indexString);
} else {
transaction.show(targetFragment);
}
transaction.commit();
mCurrentIndex = index;
}
示例12: 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());
// }
// }
}
示例13: onItemClick
import android.app.FragmentTransaction; //導入方法依賴的package包/類
@Override
public void onItemClick(int i) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// 隱藏所有的Fragment
if (exploreFragment != null)
transaction.hide(exploreFragment);
if (homeFragment != null)
transaction.hide(homeFragment);
if (settingsFragment != null)
transaction.hide(settingsFragment);
// 顯示被選中的Fragment
switch (i) {
case 0: // 動態
if (homeFragment == null) {
homeFragment = new HomeFragment();
transaction.add(R.id.container, homeFragment);
} else
transaction.show(homeFragment);
setTitle(R.string.dynamic);
break;
case 1: // 發現
if (exploreFragment == null) {
exploreFragment = new ExploreFragment();
transaction.add(R.id.container, exploreFragment);
} else
transaction.show(exploreFragment);
setTitle(R.string.explore);
break;
case 3:
if (settingsFragment == null) {
settingsFragment = new SettingsFragment();
transaction.add(R.id.container, settingsFragment);
} else
transaction.show(settingsFragment);
setTitle("設置");
}
transaction.commit();
}
示例14: initView
import android.app.FragmentTransaction; //導入方法依賴的package包/類
private void initView() {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
FileFragment fragment = FileFragment.newInstance("文件");
tx.add(R.id.framlayout, fragment,"ONE");
tx.commit();
}
示例15: onCreate
import android.app.FragmentTransaction; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
// ArcMenu arcMenu = (ArcMenu) findViewById(R.id.arc_menu);
// ArcMenu arcMenu2 = (ArcMenu) findViewById(R.id.arc_menu_2);
//
// initArcMenu(arcMenu, ITEM_DRAWABLES);
// initArcMenu(arcMenu2, ITEM_DRAWABLES);
//
// RayMenu rayMenu = (RayMenu) findViewById(R.id.ray_menu);
// final int itemCount = ITEM_DRAWABLES.length;
// for (int i = 0; i < itemCount; i++) {
// ImageView item = new ImageView(this);
// item.setImageResource(ITEM_DRAWABLES[i]);
//
// final int position = i;
// rayMenu.addItem(item, new View.OnClickListener() {
//
// @Override
// public void onClick(View v) {
// Toast.makeText(MainActivity.this, "position:" + position, Toast.LENGTH_SHORT).show();
// }
// });// Add a menu item
// }
//
//
// if (true)
// return;
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.container, FloatingViewControlFragment.newInstance());
ft.commit();
}
}