DialogFragment is called from the fragment (settings) by clicking on a TextView, in which I change the settings (language) of the application, how do I, after closing DialogFragment, apply settings without reloading the entire application? and ideally, the languages ​​should be changed immediately in the SingleChoice selection dialog. With reboot everything works. Here is the DialogFragment code:

public class LanguageDialogFragment extends DialogFragment { final String[] itemsLang = {"English", "Russian", "Ukraine"}; final String[] items = {"en", "ru", "uk"}; String lang; MainActivity activity = new MainActivity(); @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Выберите свой родной язык") .setSingleChoiceItems(itemsLang, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { lang = items[item]; } }) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { App.prefs.saveLanguage(lang); App.changeLang(lang); reload(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); return builder.create(); } private void reload() { Intent intent = getActivity().getIntent(); getActivity().finish(); Intent LaunchIntent = getActivity().getPackageManager().getLaunchIntentForPackage(App.context.getPackageName()); startActivity(LaunchIntent); } } 

Below is an example of the application I would like to implement: https://play.google.com/store/apps/details?id=com.funeasylearn.english Screenshots from it: When you select, the language changes immediately. When you select, the language changes immediately.

    1 answer 1

    Method such

     public void setLocale(String lang) { myLocale = new Locale(lang); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; res.updateConfiguration(conf, dm); Intent refresh = new Intent(getActivity(), MainActivity.class); startActivity(refresh); } 

    But you somehow need to restart the activation on which you are, so that she hooked the necessary resources. lang is a language code. for example Russian is "ru"

    • Look at the application, the link to which he gave, they somehow immediately update - Krushik
    • More similar to the fact that this is a ready translation and not the use of resources depending on locale. - pavel163
    • What do you mean by "ready translation"? - Krushik
    • That is, the program has the logic of re-creating the list and updating the screen, which was not done by dividing resources by locale - pavel163
    • Then the task comes down to what I need to understand what kind of logic it is and how to implement it in myself - Krushik