本文整理汇总了Java中android.app.FragmentTransaction.addToBackStack方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.addToBackStack方法的具体用法?Java FragmentTransaction.addToBackStack怎么用?Java FragmentTransaction.addToBackStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.addToBackStack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
}
示例3: switchToRegistration
import android.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void switchToRegistration() {
FragmentTransaction ft = fragmentManager.beginTransaction();
RegistrationFragment registrationFragment = (RegistrationFragment) fragmentManager.findFragmentByTag(REGISTER_FRAGMENT_TAG);
if (registrationFragment == null) {
registrationFragment = RegistrationFragment.newInstance();
}
ft.replace(R.id.fragmentContainer, registrationFragment, REGISTER_FRAGMENT_TAG);
ft.addToBackStack(REGISTER_FRAGMENT_TAG);
ft.commit();
}
示例4: showFragment
import android.app.FragmentTransaction; //导入方法依赖的package包/类
private void showFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(
R.animator.enter,
R.animator.exit,
R.animator.pop_enter,
R.animator.pop_exit
);
fragmentTransaction.replace(R.id.products_activity_content, fragment);
fragmentTransaction.addToBackStack("ProductsStack");
fragmentTransaction.commit();
}
示例5: show
import android.app.FragmentTransaction; //导入方法依赖的package包/类
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();
}
示例6: showEula
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public static void showEula(Activity activity) {
FragmentManager fm = activity.getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag("dialog_eula");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
new EulaDialog().show(ft, "dialog_eula");
}
示例7: onCreate
import android.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment fragment = new FragmentFeed();
ft.addToBackStack(null);
ft.replace(R.id.content_main, fragment).commit();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
示例8: replaceHasHistory
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public void replaceHasHistory(int containerId, Fragment fragment) {
if (currentFragment==fragment) {
return;
}
FragmentTransaction ft = fm.beginTransaction();
ft.replace(containerId, fragment);
ft.addToBackStack(null);//添加这个会在按返回键的时候先退出fragment,一些特殊场合可能用到,但效果其实不理想
ft.commitAllowingStateLoss();
currentFragment = fragment;
}
示例9: showPasswordResetFragment
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public void showPasswordResetFragment() {
final FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.animator.fade_in, R.animator.fade_out, R.animator.slide_in_left, R.animator.slide_out_right);
transaction.add(R.id.fragment_container, new DCResetPasswordFragment());
transaction.addToBackStack(DCResetPasswordFragment.TAG);
transaction.commit();
}
示例10: onScanFinish
import android.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void onScanFinish(Uri uri) {
ResultFragment fragment = new ResultFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ScanConstants.SCANNED_RESULT, uri);
fragment.setArguments(bundle);
android.app.FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(cordova.getActivity().getResources().getIdentifier("content", "id", cordova.getActivity().getPackageName()) , fragment);
fragmentTransaction.addToBackStack(ResultFragment.class.toString());
fragmentTransaction.commit();
}
示例11: changeFragmentForTablets
import android.app.FragmentTransaction; //导入方法依赖的package包/类
private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
if (newFragmentType == FragmentsAvailable.DIALER) {
showStatusBar();
} else {
hideStatusBar();
}
}
emptyFragment = false;
LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
if(newFragmentType == FragmentsAvailable.EMPTY){
ll.setVisibility(View.VISIBLE);
emptyFragment = true;
transaction.replace(R.id.fragmentContainer2, newFragment);
transaction.commitAllowingStateLoss();
getFragmentManager().executePendingTransactions();
} else {
if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) {
ll.setVisibility(View.VISIBLE);
if (newFragmentType == FragmentsAvailable.CONTACT_EDITOR) {
transaction.addToBackStack(newFragmentType.toString());
}
transaction.replace(R.id.fragmentContainer2, newFragment);
} else {
if (newFragmentType == FragmentsAvailable.EMPTY) {
ll.setVisibility(View.VISIBLE);
transaction.replace(R.id.fragmentContainer2, new EmptyFragment());
emptyFragment = true;
}
if (newFragmentType == FragmentsAvailable.DIALER
|| newFragmentType == FragmentsAvailable.ABOUT
|| newFragmentType == FragmentsAvailable.SETTINGS
|| newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) {
ll.setVisibility(View.GONE);
} else {
ll.setVisibility(View.VISIBLE);
transaction.replace(R.id.fragmentContainer2, new EmptyFragment());
}
/*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);
}
}*/
transaction.replace(R.id.fragmentContainer, newFragment);
}
transaction.commitAllowingStateLoss();
getFragmentManager().executePendingTransactions();
currentFragment = newFragmentType;
if (newFragmentType == FragmentsAvailable.DIALER
|| newFragmentType == FragmentsAvailable.SETTINGS
|| newFragmentType == FragmentsAvailable.CONTACTS_LIST
|| newFragmentType == FragmentsAvailable.CHAT_LIST
|| newFragmentType == FragmentsAvailable.HISTORY_LIST) {
try {
getFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (IllegalStateException e) {
}
}
fragmentsHistory.add(currentFragment);
}
}
示例12: show
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public void show(FragmentManager manager) {
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, getTagName());
ft.addToBackStack(getTagName());
ft.commit();
}
示例13: showCollectDCN
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public void showCollectDCN() {
final FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_left, R.animator.slide_in_left, R.animator.slide_out_right);
transaction.replace(R.id.fragment_container, new DCCollectDCNFragment());
transaction.addToBackStack(DCCollectDCNFragment.TAG);
transaction.commit();
}
示例14: switchFragment
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public static void switchFragment(FragmentManager fragmentManager, Fragment fragment, int containViewId, boolean addToBackStack)
{
// fragments.add(new WeakReference<Fragment>(fragment));
//
// FragmentTransaction transaction = fragmentManager.beginTransaction();
// transaction.replace(containViewId, fragment);
//// transaction.replace(containViewId, fragment, fragment.getClass().toString());
// if (addToBackStack)
// {
// backStackIndex++;
// String key = "" + backStackIndex;
// transaction.addToBackStack(key);
// backStackKeys.add(key);
// }
// else
// {
//// transaction.addToBackStack(null);
// }
//
// transaction.commit();
boolean isContain = false;
for (int i = 0; i < fragments.size(); i++){
if (fragments.get(i).get() != null && fragments.get(i).get().getClass() == fragment.getClass()){
isContain = true;
break;
}
}
if (!isContain){
fragments.add(new WeakReference<Fragment>(fragment));
}
if (fragment.getView() != null){
fragment.getView().setClickable(true);
}
FragmentTransaction transaction = fragmentManager.beginTransaction();
if (addToBackStack)
{
backStackIndex++;
String key = "" + backStackIndex;
transaction.addToBackStack(key);
backStackKeys.add(key);
}
else
{
// transaction.addToBackStack(null);
}
transaction.replace(containViewId, fragment, ""+backStackIndex);
transaction.commitAllowingStateLoss();
}
示例15: onClick
import android.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
int scenario = -1;
switch (getAdapterPosition()) {
case 0:
if (currentMeasure != null) {
switch (currentMeasure.getEscenarioStateToday()) {
case "NONE":
scenario = 0;
break;
case "ESCENARIO1":
scenario = 1;
break;
case "ESCENARIO2":
scenario = 2;
break;
case "ESCENARIO3":
scenario = 3;
break;
case "ESCENARIO4":
scenario = 4;
break;
}
}
showDialogScenario(scenario,true);
break;
case 1:
if (currentMeasure != null) {
switch (currentMeasure.getEscenarioStateTomorrow()) {
case "NONE":
scenario = 0;
break;
case "ESCENARIO1":
scenario = 1;
break;
case "ESCENARIO2":
scenario = 2;
break;
case "ESCENARIO3":
scenario = 3;
break;
case "ESCENARIO4":
scenario = 4;
break;
}
}
showDialogScenario(scenario,false);
break;
case 2:
FragmentManager fragmentManager = mActivity.getFragmentManager();
String fragment_tag = MyMapFragment.class.getName();
Fragment fragment = fragmentManager.findFragmentByTag(fragment_tag);
if (fragment == null) {
fragment = new MyMapFragment();
}
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.content_frame, fragment, fragment_tag);
transaction.addToBackStack(null);
transaction.commit();
break;
case 3:
DownloadFilesUtils.downloadPdf(mActivity, mActivity, DownloadFilesUtils.EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE_BOLETIN_DIARIO);
}
}