Marwa Shams
Marwa Shams

Reputation: 179

updating date "day/month/year" in DatePicker in Android

I want to update the date picker to a given date (day,month,year) I used this code

    date.updateDate(year, month, day);

where day,month and year are of type int. I have an exception while debugging "source not found" at this line. what's the wrong with my code?? thanks

Upvotes: 0

Views: 1020

Answers (1)

DJPlayer
DJPlayer

Reputation: 3294

Is date your view?

view.updateDate(year, month, day)

ex:

 mDateListener = new DatePicker.OnDateChangedListener() {
            public void onDateChanged(DatePicker view, int year, int month, int day) {
                if (prompt.isReadOnly()) {
                    if (prompt.getAnswerValue() != null) {
                        Date d = (Date) prompt.getAnswerObject();
                        view.updateDate(d.getYear() + YEARSHIFT, d.getMonth(), d.getDate());
                    } else {
                        view.updateDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c
                                .get(Calendar.DAY_OF_MONTH));
                    }
                } else {
                    // handle leap years and number of days in month
                    // TODO
                    // http://code.google.com/p/android/issues/detail?id=2081
                    c.set(year, month, 1);
                    int max = c.getActualMaximum(Calendar.DAY_OF_MONTH);
                    if (day > max) {
                        view.updateDate(year, month, max);
                    } else {
                        view.updateDate(year, month, day);
                    }
                }
            }
        };

Upvotes: 0

Related Questions