java - How to load Changed language in android using EasySharedPreferences -
i trying load changed language using easysharedpreferences, im having problem of how load result of saved string, here code:
public void shqiponclick(view v){ intent startmainactivity = new intent(this, mainactivity.class); startactivity(startmainactivity); languagetoload = "sq"; // language locale locale = new locale(languagetoload); locale.setdefault(locale); configuration config = new configuration(); config.locale = locale; getbasecontext().getresources().updateconfiguration(config, getbasecontext().getresources().getdisplaymetrics()); sharedpreferencedata.putstring("lang",languagetoload); } public void englishonclick(view v){ intent startmainactivity = new intent(this, mainactivity.class); startactivity(startmainactivity); languagetoload = "en"; // language locale locale = new locale(languagetoload); locale.setdefault(locale); configuration config = new configuration(); config.locale = locale; getbasecontext().getresources().updateconfiguration(config, getbasecontext().getresources().getdisplaymetrics()); sharedpreferencedata.putstring("lang",languagetoload); }
call sharedpreferences()
way:
sharedpreferences saherdpreferences = getpreferencemanager().getsharedpreferences(); sharedpreferences.editor editor = saherdpreferences.edit(); editor.putstring("string", key); editor.apply();
to retreive sharedpreferences()
:
sharedpreferences saherdpreferences = getpreferencemanager().getsharedpreferences(); string str = saherdpreferences .getstring("string", key);
Comments
Post a Comment