【问题标题】:TabLayout keeps old adapter's fragmentsTabLayout 保留旧适配器的片段
【发布时间】:2016-09-04 04:19:12
【问题描述】:

我正在尝试在按下按钮后更改 TabLayout 的内容。

我有五个片段。开始时 TabLayout 包含 1. 2. 和 3. 片段,当我按下导航抽屉按钮时,我想更改 Tablayout 使其仅包含 3. 4.

目前我不知道如何从 TabLayout 中一次删除所有片段并按照适配器的要求替换它们。

我尝试更换适配器(它不包含任何提及片段 1、2 和 3),将适配器设置为 null,以各种组合调用 .notifyDataSetChanged();。但是我想出的任何东西都不会迫使 TabLayout 实际更新自身并摆脱旧片段并用新片段替换它们。

我只设法用这个更新了 tablayout 中的第一个片段,然后显示正确的片段(适配器实际告诉的内容):

                Fragment fragment = getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":" + viewPager.getCurrentItem());
                if (fragment != null) // could be null if not instantiated yet
                {
                    if (fragment.getView() != null) {
                        // Pop the backstack on the ChildManager if there is any. If not, close this activity as normal.
                        fragment.getActivity().getSupportFragmentManager().beginTransaction().remove(fragment).commit();

                    }
                }

我怎么能做我想做的事?

【问题讨论】:

    标签: android android-fragments android-viewpager android-tablayout navigation-drawer


    【解决方案1】:

    问题似乎已解决,我刚刚将所有内容更新到最新版本。我希望其他人永远不会遇到这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-07
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      相关资源
      最近更新 更多