DatePicker crashes on my device when clicked (with personal app)

前端 未结 7 2019
长发绾君心
长发绾君心 2020-12-12 13:46

Edit : I checked that the issue only appears when the phone is set with \"French\" language.

I\'m currently building my own app and I have an issue

7条回答
  •  孤城傲影
    2020-12-12 14:35

    I find a workaround, playing with configuration and Locale variables.

    I juste modify the language if I detect it's a french ("fr") language and replace it with an english ("en") language, then put back to normal once out of the DatePicker DialogFragment.

    public void showDatePickerDialog(int layoutId) {
            Integer year = cal.get(Calendar.YEAR);
            Integer month = cal.get(Calendar.MONTH);
            Integer day = cal.get(Calendar.DAY_OF_MONTH);
    
            // Due to an issue with DatePicker and fr language (locale), if locale language is french, this is changed to us to make the DatePicker working
            if(Locale.getDefault().getLanguage().toString().equals(FR_LANG_CONTEXT)){
                Configuration config = new Configuration();
                config.locale = new Locale(US_LANG_CONTEXT);
                getApplicationContext().getResources().updateConfiguration(config, null);
            }
    
            Bundle bundle = createDatePickerBundle(layoutId, year, month, day);
            DialogFragment newFragment = new DatePFragment();
            newFragment.setArguments(bundle);
            newFragment.show(fm, Integer.toString(layoutId));
        }
    

    And once I'm out

    @Override
        public void onDatePicked(int LayoutId, int year, int month, int day){
            // Once out from the DatePicker, if we were working on a fr language, we update back the configuration with fr language.
            if(Locale.getDefault().getLanguage().toString().equals(FR_LANG_CONTEXT)){
                Configuration config = new Configuration();
                config.locale = new Locale(FR_LANG_CONTEXT);
                getApplicationContext().getResources().updateConfiguration(config, null);
            }
    
            String date = day + "/" + month + "/" + year;
            txtTaskDate.setText(date);
        }
    

提交回复
热议问题