I use below code to force my textview to show its text numbers with English digits:
txtScale.setText("x" + String.format(Locale.ENGLISH, String.valueOf(scaleValue)));
but it is not working and keep showing the numbers with selected locale. If application locale set to Arabic, it show numbers to Arabic, if set to English it show them English but I want to force to show numbers in English at all states.
For example I want to show below text in Arabic:
۱۲۳۴ //are one two three four
As:
1234
If it helps, I use below code for changing the language of the app manually:
Locale locale = new Locale(CurrentLanguage);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
Not very sure what you need, but I guess you need this:
txtScale.setText(String.format(Locale.ENGLISH, "x%d", scaleValue));
String.valueOf(scaleValue)
there error was here, where you have converted the number based on default Locale
I have had the same problem, the solution was to concatenate the number variable with an empty string. For example like this :
public void displayPoints(){
TextView scoreA = findViewById(R.id.score_id);
scoreA.setText(""+points);
}
I used this
scoreA.setText(""+points);
instead of this
scoreA.setText(String.format("%d",points));
this will even give you a warning that hardcoded text can not be properly translated to other languages, which exactly what we want here :) .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With