Welcome to OGeek Q&A 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...