Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

localization - Set language to French in android DatePickerDialog

Is there any way to have date displayed in DatePickerDialog in french

I have searched about this but found no results

Here is my code:

 Calendar c = Calendar.getInstance();

 picker = new DatePickerDialog(PaymentView.this, 
                               PaymentView.this,
                   c.get(Calendar.YEAR), 
                               c.get(Calendar.MONTH),
                   c.get(Calendar.DAY_OF_MONTH));

 picker.setIcon(R.drawable.ic_launcher);
 picker.setTitle("Choisir la date");
 picker.getDatePicker().setMinDate(System.currentTimeMillis() - 2000);

Instead of Fri, Nov 21, 2014 I want to have french abbreviation I have also added that before instantiate it :

 Locale locale = new Locale("FR");
 Locale.setDefault(locale);
 Configuration config = new Configuration();
 config.locale = locale;
 getApplicationContext().getResources().updateConfiguration(config, null);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I made it!

I have added these 2 lines before all the DatePickerDialog stuff:

Locale locale = getResources().getConfiguration().locale;
Locale.setDefault(locale);

and after that:

Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(MainActivity.this,
            this, mYear, mMonth, mDay);
dialog.getDatePicker().setMaxDate(c.getTimeInMillis());
dialog.setTitle(R.string.main_first_day_of_your_last_period);
dialog.show();

I hope it helps someone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...