Im having problem in passing the language locale to a string.
Code is very simple, and i can display the language whit a toast, but i cannot set inside a text.
In this moment, language returns: "it", "fr", "en".
//helperLang.setText("Italian"); is commented because app get crash.
My code:
public void loadLocale(){
SharedPreferences preferences = getSharedPreferences("Settings", Activity.MODE_PRIVATE);
String language = preferences.getString("My_Lang","");
helperLang = findViewById(R.id.helperText_lang);
if(language.equals("it")){
//helperLang.setText("Italian");
Toast.makeText(this, "italian", Toast.LENGTH_SHORT).show();
}else if(language.equals("fr")){
// helperLang.setText("French");
Toast.makeText(this, "French", Toast.LENGTH_SHORT).show();
}else{
// helperLang.setText("English");
Toast.makeText(this, "English", Toast.LENGTH_SHORT).show();
}
}
I was declaring
helperLang.setText("Italian")inside the method, but actually, it goes outside on global scope. Then i modified my method as follow: