Search code examples
javaandroiddatepickerlocale

Android: how to change DatePicker values


I'm creating application that includes DatePicker, is there any way to change his values?

For example:

My DatePicker looks like this: Dec 08 2013 And I want it to look: Gruodis 08 2013 //Gruodis means December in lithuanian.

So is there any way to change month values so DatePicker would be showed with lithuanian month names when I'm choosing the date?


Solution

  • I think you should get the locale but just wrapped to your app context. Try:

    Locale locale = new Locale("lt");
    Resources res = getResources();
    android.content.res.Configuration conf = res.getConfiguration();
    DisplayMetrics dm = res.getDisplayMetrics();
    conf.locale = locale;
    res.updateConfiguration(conf, dm);
    

    Edit: if your locale is not available, you will have to implement the DatePicker on your own to make the strings available in your language 'cause the spinners used are private to the class so you cannot inherit it to modify that behavior.

    An then creating the DatePicker dialog (or DatePicker itself). Regards.