Skip to content Skip to sidebar Skip to footer

Android: Refresh Current Fragment After Language Change

So my MainActivity has a navigation drawer with a set of fragments. On top of the nav bar, I have 2 flags which represent a language. If an user clicks on a language, the app chan

Solution 1:

Add tag to your fragment when you commit it:

fragmentManager.beginTransaction().replace(R.id.your_id, fragment, "Your_Fragment_TAG").commitAllowingStateLoss();

Then You can detach and attach again your fragment for refresh:

// Reload current fragmentFragmentfrg=null;
frg = getSupportFragmentManager().findFragmentByTag("Your_Fragment_TAG");
finalFragmentTransactionft= getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();

Post a Comment for "Android: Refresh Current Fragment After Language Change"