1. <i id='U5DRs'><tr id='U5DRs'><dt id='U5DRs'><q id='U5DRs'><span id='U5DRs'><b id='U5DRs'><form id='U5DRs'><ins id='U5DRs'></ins><ul id='U5DRs'></ul><sub id='U5DRs'></sub></form><legend id='U5DRs'></legend><bdo id='U5DRs'><pre id='U5DRs'><center id='U5DRs'></center></pre></bdo></b><th id='U5DRs'></th></span></q></dt></tr></i><div id='U5DRs'><tfoot id='U5DRs'></tfoot><dl id='U5DRs'><fieldset id='U5DRs'></fieldset></dl></div>
    1. <legend id='U5DRs'><style id='U5DRs'><dir id='U5DRs'><q id='U5DRs'></q></dir></style></legend>
    2. <small id='U5DRs'></small><noframes id='U5DRs'>

        <bdo id='U5DRs'></bdo><ul id='U5DRs'></ul>
    3. <tfoot id='U5DRs'></tfoot>
    4. 如何在我的 Activity 中重新启动 Fragment - Android

      时间:2023-10-04

        <small id='84Jyz'></small><noframes id='84Jyz'>

      1. <legend id='84Jyz'><style id='84Jyz'><dir id='84Jyz'><q id='84Jyz'></q></dir></style></legend>

          <i id='84Jyz'><tr id='84Jyz'><dt id='84Jyz'><q id='84Jyz'><span id='84Jyz'><b id='84Jyz'><form id='84Jyz'><ins id='84Jyz'></ins><ul id='84Jyz'></ul><sub id='84Jyz'></sub></form><legend id='84Jyz'></legend><bdo id='84Jyz'><pre id='84Jyz'><center id='84Jyz'></center></pre></bdo></b><th id='84Jyz'></th></span></q></dt></tr></i><div id='84Jyz'><tfoot id='84Jyz'></tfoot><dl id='84Jyz'><fieldset id='84Jyz'></fieldset></dl></div>
            <tbody id='84Jyz'></tbody>
                <bdo id='84Jyz'></bdo><ul id='84Jyz'></ul>

                <tfoot id='84Jyz'></tfoot>
                本文介绍了如何在我的 Activity 中重新启动 Fragment - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个活动,里面有 3 个片段.我需要通过单击按钮重新启动我的活动中的第一个片段.

                I have an activity that have 3 fragment inside. I need restart a first fragment in my activity with click on Button.

                ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
                adapter.addFrag(new HomeFragment(), "Home");
                adapter.addFrag(new CategoryFragment(), "Category");
                adapter.addFrag(new FilterFragment(), "Filter");
                viewPager.setAdapter(adapter);
                

                我测试了以下方式,但不起作用并显示错误:在重新加载时刷新片段

                I test the following way but doesn't work and show error: refresh fragment at reload

                java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.Fragment.setNextAnim(int)' on a null object reference 
                

                推荐答案

                你可以用这个重新加载你的片段:

                You can reload your fragment with this:

                FragmentTransaction tr = getFragmentManager().beginTransaction();
                tr.replace(R.id.fragment_layout, instanceFragment);
                tr.commit()
                

                作为 instanceFragment 您要重新加载的片段实例和 fragment_layout 在您的活动布局 XML 文件中的 FrameLayout 组件.

                Being instanceFragment the instance of the fragment you wanna to reload and fragment_layout the FrameLayout component in your activity layout XML file.

                这篇关于如何在我的 Activity 中重新启动 Fragment - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Toast 类型中的方法 makeText 不适用于参数 下一篇:在 ViewPager 中从 Activity 更新片段

                相关文章

              • <tfoot id='f0maN'></tfoot>
                  <bdo id='f0maN'></bdo><ul id='f0maN'></ul>
                  <i id='f0maN'><tr id='f0maN'><dt id='f0maN'><q id='f0maN'><span id='f0maN'><b id='f0maN'><form id='f0maN'><ins id='f0maN'></ins><ul id='f0maN'></ul><sub id='f0maN'></sub></form><legend id='f0maN'></legend><bdo id='f0maN'><pre id='f0maN'><center id='f0maN'></center></pre></bdo></b><th id='f0maN'></th></span></q></dt></tr></i><div id='f0maN'><tfoot id='f0maN'></tfoot><dl id='f0maN'><fieldset id='f0maN'></fieldset></dl></div>

                    <legend id='f0maN'><style id='f0maN'><dir id='f0maN'><q id='f0maN'></q></dir></style></legend>
                  1. <small id='f0maN'></small><noframes id='f0maN'>