Android DatePickerDialog default date is Jan/1/1900

血红的双手。 提交于 2020-06-16 06:58:10

问题


I can't figure out this stupid little bug. Whenever I initiate the DatePickerDialog, the default set date date is Jan/01/1900.

It's weird though because on the tablet there's a calendar view next to the slider which you can pick from as well and THATS set on the current date, but the slider isn't.

public static class DatePickerFragment extends DialogFragment implements
        DatePickerDialog.OnDateSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Log.d("month",Integer.toString(mMonth)); //Is returning current month, like it should

        return new DatePickerDialog(getActivity(), this, mDay, mMonth, mYear); //all set to current date
    }

    public void onDateSet(DatePicker view, int year, int month, int day) {
        dateDue.setText(month + 1 + "/" + day + "/" + year);
    }
}

回答1:


I'm an idiot. Order of parameters in constructor is year, month then date.



来源:https://stackoverflow.com/questions/19184834/android-datepickerdialog-default-date-is-jan-1-1900

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!