导航到先前的片段而无需重新加载 [英] Navigating to previous fragment without reloading it
本文介绍了导航到先前的片段而无需重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个正在使用片段的应用程序.我想从另一个片段返回到先前的片段,而无需重新加载先前的片段.
I am creating an app in which I'm using fragments. I want to go back to the previous fragment from another fragment without reloading the previous fragment.
转到下一个片段的代码:
Code for going to the next fragment:
Fragment newFragment;
android.support.v4.app.FragmentManager manager = ((AppCompatActivity) context).getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
newFragment = new Inner_details();
transaction.replace(R.id.content_data, newFragment);
transaction.addToBackStack("fragment6");
transaction.commit();
转到上一个片段的代码
FragmentManager fm = getActivity().getSupportFragmentManager();
fm.popBackStack ("fragment6", FragmentManager.POP_BACK_STACK_INCLUSIVE);
推荐答案
您正在替换片段,因此先前的片段将不再具有其内容,您可以尝试通过添加"而不是替换"加载片段:
you are replacing your fragments so the previous fragment will no longer be available with its content, you might try to load your fragments by "add" instead of "replace":
transaction.add(R.id.content_data, newFragment);
这篇关于导航到先前的片段而无需重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文