我曾经DatePicker
根据用户输入的生日日期来计算年龄。现在我想限制用户选择未来的日期......这是我在mainActivity.java
@SuppressLint("NewApi")
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int mBirthYear = c.get(Calendar.YEAR);
int mMonthOfYear = c.get(Calendar.MONTH);
int mDayOfMonth= c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, mBirthYear,mMonthOfYear ,mDayOfMonth );
}
public void onDateSet(DatePicker view, int mBirthYear, int mMonthOfYear, int mDayOfMonth)
{
int mAge;
mAge = Year-mBirthYear;
if ((mMonthOfYear == Month && Day < mDayOfMonth) || ( Month < mMonthOfYear) )
{
mAge--;
}
String years = String.valueOf(mAge);
MainActivity.textView6.setText(years);