android - java.lang.ClassCastException: ListActivity cannot be cast to DatePickerDialog -
i'm having problems implement material datepicker due context call should doing wrong.
the sample github works fine because dialog being created activity.
however, @ particular case, i'm working fragment attached listactivity.
this how i'm calling it:
calendar = calendar.getinstance(); datepickerdialog dpd = datepickerdialog.newinstance( (datepickerdialog.ondatesetlistener) getactivity(), now.get(calendar.year), now.get(calendar.month), now.get(calendar.day_of_month) ); dpd.show(getfragmentmanager(), "datepickerdialog"); this line (datepickerdialog.ondatesetlistener) getactivity() generating issue. declared mainactivity.this in sample, can't use listactivity.this or similar.
logcat
process: kva.ihm, pid: 16218 java.lang.classcastexception: kva.ihm.parameterlistactivity cannot cast com.wdullaer.materialdatetimepicker.date.datepickerdialog$ondatesetlistener @ kva.ihm.parameterdetailfragment$49.onitemclick(parameterdetailfragment.java:3839)
your activity should implement datepickerdialog.ondatesetlistener handling callback void ondateset(datepickerdialog dialog, int year, int monthofyear, int dayofmonth); datepicker.
or can handle using anonim class:
datepickerdialog dialog = datepickerdialog.newinstance(new datepickerdialog.ondatesetlistener() { @override void ondateset(datepickerdialog dialog, int year, int monthofyear, int dayofmonth) { //your code. } }, year, monthofyear, dayofmonth);
Comments
Post a Comment