代码:
final Time today = new Time();
today.setToNow();
OnDateChangedListener dateChangeListener = new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
android.util.Log.i(TAG, "entered onDateChanged"); //TODO:
}
};
datePickerDataInicio.init(today.year, today.month, today.monthDay, dateChangeListener);
因此,每当我从日,月或年改变旋转器时,似乎都没有调用。我错过了什么?
谢谢!
修改<!/强>
对不起伙计们,这是注意力的缺陷。我只是使用null侦听器从代码的另一个点调用DatePicker.init()
。感谢。
答案 0 :(得分:1)
尝试此代码,它正在运行..
// Creating dialog
@Override
protected Dialog onCreateDialog(int id) {
c = Calendar.getInstance();
int cyear = c.get(Calendar.YEAR);
int cmonth = c.get(Calendar.MONTH);
int cday = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday);
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
// onDateSet method
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Log.e("----------------", "D.O.B "+monthOfYear+""+dayOfMonth+""+year);
date_selected = String.valueOf(monthOfYear+1)+" /"+String.valueOf(dayOfMonth)+" /"+String.valueOf(year);
}
};
在点击任何按钮或文本
时调用此方法DATE_DIALOG_ID=1;
showDialog(DATE_DIALOG_ID);