本文整理匯總了Java中android.app.FragmentManager.beginTransaction方法的典型用法代碼示例。如果您正苦於以下問題:Java FragmentManager.beginTransaction方法的具體用法?Java FragmentManager.beginTransaction怎麽用?Java FragmentManager.beginTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.FragmentManager
的用法示例。
在下文中一共展示了FragmentManager.beginTransaction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onNavigationItemSelected
import android.app.FragmentManager; //導入方法依賴的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;
}
示例2: removeFragment
import android.app.FragmentManager; //導入方法依賴的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");
}
}
示例3: initializeFragments
import android.app.FragmentManager; //導入方法依賴的package包/類
/**
* Create fragment instances if necessary.
*
* @see #findFragments()
*/
private void initializeFragments() {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.addOnBackStackChangedListener(this);
boolean hasMessageListFragment = (mMessageListFragment != null);
if (!hasMessageListFragment) {
FragmentTransaction ft = fragmentManager.beginTransaction();
mMessageListFragment = MessageListFragment.newInstance(mSearch, false,
(QMail.isThreadedViewEnabled() && !mNoThreading));
ft.add(R.id.message_list_container, mMessageListFragment);
ft.commit();
}
// Check if the fragment wasn't restarted and has a MessageReference in the arguments. If
// so, open the referenced message.
if (!hasMessageListFragment && mMessageViewFragment == null &&
mMessageReference != null) {
openMessage(mMessageReference);
}
}
示例4: onOptionsItemSelected
import android.app.FragmentManager; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
SettingFragment preference=new SettingFragment();
try {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, preference);
fragmentTransaction.addToBackStack(null); // 戻るボタンでreplace前に戻る
fragmentTransaction.commit();
} catch (Exception e) {
SdLog.log(e);
}
return true;
}
return super.onOptionsItemSelected(item);
}
示例5: initView
import android.app.FragmentManager; //導入方法依賴的package包/類
private void initView() {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
FileFragment fragment = FileFragment.newInstance("文件");
tx.add(R.id.framlayout, fragment,"ONE");
tx.commit();
}
示例6: showCamera
import android.app.FragmentManager; //導入方法依賴的package包/類
private boolean showCamera(CallbackContext callbackContext) {
if(this.hasView(callbackContext) == false){
return true;
}
FragmentManager fragmentManager = cordova.getActivity().getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.show(fragment);
fragmentTransaction.commit();
callbackContext.success();
return true;
}
示例7: prepareSettings
import android.app.FragmentManager; //導入方法依賴的package包/類
private void prepareSettings() {
String title, fragId;
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
title = bundle.getString("title");
fragId = bundle.getString("frag_id");
} else {
title = getString(R.string.preference);
fragId = "GeneralSettingsFragment";
}
TextView textView = (TextView) findViewById(R.id.settings_bar);
textView.setText(title);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if ("GeneralSettingsFragment".equals(fragId)) {
fragmentTransaction.replace(R.id.preferences_fragment, new GeneralSettingsFragment());
} else if ("CommentSettingsFragment".equals(fragId)) {
fragmentTransaction.replace(R.id.preferences_fragment, new CommentSettingsFragment());
}
fragmentTransaction.commit();
}
示例8: setupTransaction
import android.app.FragmentManager; //導入方法依賴的package包/類
/**
* Setup a base dialog fragment transaction. Handles the removing of a
* previous fragment if it exists and adds itself to the backstack.
*
* @return FragmentTransaction
*/
private FragmentTransaction setupTransaction(Activity activity) {
FragmentManager manager = activity.getFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
Fragment prev = manager.findFragmentByTag("dialog");
if (prev != null)
ft.remove(prev);
ft.addToBackStack(null);
return ft;
}
示例9: onCreate
import android.app.FragmentManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MapPrefFragment settingsFragment = new MapPrefFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(android.R.id.content, settingsFragment);
fragmentTransaction.commit();
}
示例10: clearAllBackStackFragments
import android.app.FragmentManager; //導入方法依賴的package包/類
public static void clearAllBackStackFragments(FragmentManager fragmentManager)
{
FragmentTransaction ft = fragmentManager.beginTransaction();
for (WeakReference<Fragment> ref : fragments) {
Fragment fragment = ref.get();
if (fragment != null) {
ft.remove(fragment);
}
}
fragments.clear();
backStackKeys.clear();
ft.commitAllowingStateLoss();
}
示例11: showChangeLogDialog
import android.app.FragmentManager; //導入方法依賴的package包/類
public static void showChangeLogDialog(FragmentManager fragmentManager) {
ChangelogDialog changelogDialog = new ChangelogDialog();
FragmentTransaction ft = fragmentManager.beginTransaction();
Fragment prev = fragmentManager.findFragmentByTag("changelogdemo_dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
changelogDialog.show(ft, "changelogdemo_dialog");
}
示例12: show
import android.app.FragmentManager; //導入方法依賴的package包/類
public static void show(FragmentManager fm, ArrayList<DocumentInfo> docs, boolean deleteAfter) {
final Bundle args = new Bundle();
args.putParcelableArrayList(EXTRA_DOC_LIST, docs);
args.putBoolean(EXTRA_DELETE_AFTER, deleteAfter);
final MoveFragment fragment = new MoveFragment();
fragment.setArguments(args);
final FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container_save, fragment, TAG);
ft.commitAllowingStateLoss();
}
示例13: onCreate
import android.app.FragmentManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SettingsFragment settingsFragment = new SettingsFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(android.R.id.content, settingsFragment);
fragmentTransaction.commit();
}
示例14: show
import android.app.FragmentManager; //導入方法依賴的package包/類
public static void show(FragmentManager fm) {
final PickFragment fragment = new PickFragment();
final FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container_save, fragment, TAG);
ft.commitAllowingStateLoss();
}
示例15: onCreate
import android.app.FragmentManager; //導入方法依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_main_db3);
super.onCreate(savedInstanceState);
mFragment = TableViewerFragment.newInstance("db3.db", "name");
mFragment.setOnItemClicked(this);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.flFragment, mFragment, "TAG").commit();
}