My app supports multiple languages. The number picker in all the languages is showing correctly. number picker in English and other languages
But when the app language is selected as Hindi, then number picker doesn't show the digits initially and shows in Hindi when the number picker is scrolled.
Number picker in Hindi when the digits are scrolled
I have tried to change the type face also and it is working in all the other languages except Hindi. Could anyone let me know how to prevent the number picker from changing the digits in Hindi language?
This is the class for my custom number picker.
public class MyNumberPicker extends NumberPicker{
public MyNumberPicker(Context context) {
super(context);
}
public MyNumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void addView(View child){
super.addView(child);
updateView(child);
}
public void addView(View child,int index,ViewGroup.LayoutParams params){
super.addView(child,index,params);
updateView(child);
}
public void addView(View child,ViewGroup.LayoutParams params){
super.addView(child,params);
updateView(child);
}
private void updateView(View view) {
if (view instanceof EditText){
((EditText)view).setTextSize(20);
((EditText)view).setTextColor(getResources().getColor(R.color.Text));
Typeface tf = Typeface.createFromAsset(getResources().getAssets(), "Raleway-Medium.ttf");
((EditText)view).setTypeface(tf);
}
}
}
This is how I have used the number picker in activity.
MyNumberPicker np_inhale =(MyNumberPicker) findViewById(R.id.np_inhale);
np_inhale.setMinValue(1);
np_inhale.setMaxValue(50);
np_inhale.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
i=newVal;
h=np_hold.getValue();
e=np_exhale.getValue();
hafter= np_holdafter.getValue();
r=np_rounds.getValue();
}
});
I have used this code for the localization.
String str_lang = "";
if (lang_chng == 1) {
str_lang = "hi";
} else if(lang_chng == 2) {
str_lang = "ru";
} else if(lang_chng == 3) {
str_lang = "fr";
}
else
str_lang = "en";
myLocale = new Locale(str_lang);
Locale.setDefault(myLocale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = myLocale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
Thanks.!