我有值Birthdate但我想在datepicker对话框中显示/选择生日。例如1997年3月1日 - >在datepicker对话框中选择此日期。我试过但只是错误。我无法找到错误的位置。
CODE:
public void setDate(){
dateView = (TextView) findViewById(R.id.showBirthDate);
//get birthday
int id = Integer.parseInt(dbhandler.getLatestProfileId());
String data=dbhandler.getBirthdate(id);
//split string for date
String[] parts = data.split("/");
month = Integer.parseInt(parts[0]);
day = Integer.parseInt(parts[1]);
year = Integer.parseInt(parts[2]);
//current
calendar = Calendar.getInstance();
calendar.set(Calendar.DATE, day);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.YEAR, year);
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
showDate(year, month, day);
}
答案 0 :(得分:1)
您可以在初始化期间在日期选择器对话框中设置日期,如下所示:
datePickerDialog = new DatePickerDialog(
context,
null,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
);