2016-10-17 12 views
0

私のAndroidアプリケーションには、18年前のmaxDateを持つカレンダーが必要です。これまでのところ、私はこのコードを試みたが、それだけで良く見るあなたの問題を理解するためにInteger number is too largeAndroidスタジオカレンダーセットmaxDate 18年前

@Override 
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 
    view.setMaxDate(System.currentTimeMillis() - 31556926000); 
    year_x = year; 
    month_x = monthOfYear + 1; 
    day_x = dayOfMonth; 
    etBirthDate.setText(month_x + "/" + day_x + "/" + year_x); 
} 
}; 

答えて

1

を言う:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.htmlセクション整数リテラル。 以下のように書かれています。

整数のリテラルは、文字LまたはLで終わる場合はlong型です。それ以外の場合はint型です。

view.setMaxDate(System.currentTimeMillis() - 31556926000L); 

しかし、私は一緒に行くでしょう:

小文字のlは数字1

最も簡単な解決策と区別するのは難しいですので、あなたが大文字のLを使用することをお勧めします

Calendar calendar = Calendar.getInstance(); 
calendar.add(Calendar.YEAR, -18); 
view.setMaxDate(calendar.getTimeInMillis()); 
-1
final Calendar mcurrentDate = Calendar.getInstance(); 
    int mYear = mcurrentDate.get(Calendar.YEAR); 
    int mMonth = mcurrentDate.get(Calendar.MONTH); 
    int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH); 


    DatePickerDialog mDatePicker = new DatePickerDialog(
      getContext(), new DatePickerDialog.OnDateSetListener() { 
     public void onDateSet(DatePicker datepicker, 
           int selectedyear, int selectedmonth, 
           int selectedday) { 
      selectedyear=selectedyear; 
      mcurrentDate.set(Calendar.YEAR, selectedyear); 
      mcurrentDate.set(Calendar.MONTH, selectedmonth); 
      mcurrentDate.set(Calendar.DAY_OF_MONTH, selectedday); 
      SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.US); 
      edtxtDOB.setText(sdf.format(mcurrentDate.getTime())); 


     } 
    }, mYear-18, mMonth, mDay); 
    mcurrentDate.set(mYear-18,mMonth,mDay); 
    long value=mcurrentDate.getTimeInMillis(); 
    mDatePicker.getDatePicker().setMaxDate(value); 
    mDatePicker.show(); 
関連する問題