设置DatePicker不起作用?

时间:2014-06-05 04:55:12

标签: java android android-datepicker

我正在尝试将我的DatePicker设置为我活动的OnCreate方法中的当前日期:

    DatePicker dp = (DatePicker) findViewById(R.id.datePicker);
    Calendar c = Calendar.getInstance();
    int day = c.get(Calendar.DAY_OF_MONTH);
    int month = c.get(Calendar.MONTH);
    int year = c.get(Calendar.YEAR);
    dp.updateDate(year, month, day);

然而,这似乎没有改变它?

2 个答案:

答案 0 :(得分:0)

试试这个

Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datedialog = new DatePickerDialog(Activity.this, mDateSetListener, year, month, day);
datedialog.show();

答案 1 :(得分:0)

只是为了让大家知道,该代码实际上工作正常我的问题是我的设备的日期是错误的!抱歉:)