每个人,我的问题是:
我在ProfilFragment中,它是通过菜单抽屉生成的,它扩展了Fragment,但我无法更改它(它破坏了其他部分)。当我单击一个按钮时,我想刷新我的当前片段
// Reload current fragment
Fragment frg = null;
frg = getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_profil);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
我在其他StackOverflow问题上发现了此问题,但对我而言不起作用。frg = getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_profil);
一律返回null
即使在我的mobile_navigation.xml
中我有
<fragment
android:id="@+id/nav_profil"
android:name="com.example.pierregignoux.ui.profil.ProfilFragment"
tools:layout="@layout/fragment_profil" />
任何帮助都会很大,非常感谢。
只需运行此
getActivity().getSupportFragmentManager().beginTransaction().detach(this).attach(this).commit();