Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a locale for textviews in fragment

I want to set locale for a single text view . Which means only that textview will be shown in another language (in my example french) but unfortunately it is not working. While I do not get an error, nothing happens.

 Locale locale = new Locale("fr");
 maintext.setTextLocale(locale);
tried updating confguirations , same thing . Nothing changes .

 Locale locale = new Locale("fr");
Configuration config = new Configuration();
config.locale = locale;
getActivity().getResources().updateConfiguration(config,
    getActivity().getResources().getDisplayMetrics());
maintext.setTextLocale(locale);

I tried doing that in normal activities and it worked perfectly fine .

like image 330
Metalloid66 Avatar asked Sep 12 '25 09:09

Metalloid66


1 Answers

You can use String.format() with Locale.FRENCH to localize the text of that TextView.

example

String txtFrench = String.format(Locale.FRENCH, "%s", item.getFrenchName());
mFrenchTextView.setText(txtFrench);
like image 168
Khalid ElSayed Avatar answered Sep 14 '25 22:09

Khalid ElSayed