Android Using Data Out Of Datepicker
Im trying to get the Day / Month / Year from my datepicker. I have the problem that the Month en the day never is correct. I give you the code below. The month is correct but it fa
Solution 1:
Why do you use the view values, not the values passed in the method? Also no need for the special case of month == 11. Try this code (modified your own):
publicvoidonDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth){
if (view.getId() == R.id.datePicker1) {
startDay = dayOfMonth;
startMonth = monthOfYear + 1;
startYear = year;
}
if (view.getId() == R.id.datePicker2) {
endDay = dayOfMonth;
endMonth = monthOfYear + 1;
endYear = year;
}
}
EDIT: After reading your comment I feel the problem you get might be because of some other confusion on your side: I mean the fact that the Java Date class constructor that goes like this:
public Date(intyear, intmonth, intdate)
Initializes the date starting from 1st of January 1900th year. Warning: the month is between 0 and 11 and the day between 1 and 31. Take a look at the constructor. If you want to detect whether the problem is in the DatePicker itself or after that in the Java code try logging to narrow the scope of causes.
Post a Comment for "Android Using Data Out Of Datepicker"