public void selectDate()//选择生日,设置年龄
{
final Calendar calendar = Calendar.getInstance();
DatePickerDialog datePickerDialog = new DatePickerDialog(
getActivity(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view,
int year, int monthOfYear,
int dayOfMonth) {
yearint = year;
monthint = monthOfYear;
dayint = dayOfMonth;
txtbirth.setText(year + "/" + (monthOfYear + 1) + "/" + dayOfMonth);
Calendar nowCalendar = Calendar.getInstance();
// 算年龄
int age = nowCalendar.get(Calendar.YEAR) - year;
if (age <= 0) {
txtage.setText("错误");
} else {
txtage.setText(age + "");
}
}
}, calendar.get(Calendar.YEAR), calendar
.get(Calendar.MONTH), calendar
.get(Calendar.DAY_OF_MONTH));
datePickerDialog.setCancelable(true);
datePickerDialog.show();
}