1、主代码
/** * 日期选择器 */ private DatePickerDialog datePickerDialog; /** * 年 */ private int mYear=1993; /** * 月 */ private int mMonth=12-1; /** * 日 */ private int mDay=16; ......................... //构造函数包括mYear, mMonth, mDay用来显示初始日期,同时设置监听 datePickerDialog = new DatePickerDialog(UserInfoActivity.this, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; birTextView.setText(new StringBuilder().append(mYear) .append("-").append(mMonth + 1).append("-") .append(mDay)); } }, mYear, mMonth, mDay); ...................................... datePickerDialog.show();
Done!