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);