android - InflateException DatePicker -
i trying show datepickerdialog in fragment when user clicks edittext
//initialise calendar newcalendar = calendar.getinstance(); datepickerdialog = new datepickerdialog(getactivity(), new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int year, int month, int day) { etdate.settext(day + "/" + month + "/" + year); } },newcalendar.get(calendar.year), newcalendar.get(calendar.month), newcalendar.get(calendar.day_of_month)); //show on click datepickerdialog.show();
the problem is ends with:
fatal exception: main process: tvfriends.kolio.com.tvproba, pid: 26562 android.view.inflateexception: binary xml file line #18: binary xml file line #18: error inflating class android.widget.datepicker caused by: android.view.inflateexception: binary xml file line #18: error inflating class android.widget.datepicker caused by: java.lang.reflect.invocationtargetexception @ java.lang.reflect.constructor.newinstance0(native method) @ java.lang.reflect.constructor.newinstance(constructor.java:430) @ android.view.layoutinflater.createview(layoutinflater.java:645) @ com.android.internal.policy.phonelayoutinflater.oncreateview(phonelayoutinflater.java:58) @ android.view.layoutinflater.oncreateview(layoutinflater.java:717) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:785) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:727) @ android.view.layoutinflater.inflate(layoutinflater.java:495) @ android.view.layoutinflater.inflate(layoutinflater.java:426) @ android.view.layoutinflater.inflate(layoutinflater.java:377) @ android.app.datepickerdialog.<init>(datepickerdialog.java:119) @ android.app.datepickerdialog.<init>(datepickerdialog.java:90) @ tvfriends.kolio.com.tvproba.activities.hostactivity$datepickerfragment.oncreatedialog(hostactivity.java:311) @ android.support.v4.app.dialogfragment.getlayoutinflater(dialogfragment.java:307) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1104) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1286) @ android.support.v4.app.backstackrecord.run(backstackrecord.java:758) @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1671) @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:532) @ android.os.handler.handlecallback(handler.java:751) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:154) @ android.app.activitythread.main(activitythread.java:6077) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:865) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:755) caused by: android.content.res.resources$notfoundexception: drawable android:color/tab_indicator_text resource id #0x1060009 caused by: android.content.res.resources$notfoundexception: file res/color/tab_indicator_text.xml drawable resource id #0x1060009 @ android.content.res.resourcesimpl.loaddrawableforcookie(resourcesimpl.java:725) @ android.content.res.resourcesimpl.loaddrawable(resourcesimpl.java:571) @ android.content.res.resources.loaddrawable(resources.java:854) @ android.content.res.typedarray.getdrawable(typedarray.java:924) @ android.widget.datepickercalendardelegate.<init>(datepickercalendardelegate.java:155) @ android.widget.datepicker.createcalendaruidelegate(datepicker.java:143) @ android.widget.datepicker.<init>(datepicker.java:123) @ android.widget.datepicker.<init>(datepicker.java:109) @ android.widget.datepicker.<init>(datepicker.java:105) @ java.lang.reflect.constructor.newinstance0(native method) @ java.lang.reflect.constructor.newinstance(constructor.java:430) @ android.view.layoutinflater.createview(layoutinflater.java:645) @ com.android.internal.policy.phonelayoutinflater.oncreateview(phonelayoutinflater.java:58) @ android.view.layoutinflater.oncreateview(layoutinflater.java:717) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:785) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:727) @ android.view.layoutinflater.inflate(layoutinflater.java:495) @ android.view.layoutinflater.inflate(layoutinflater.java:426) @ android.view.layoutinflater.inflate(layoutinflater.java:377) @ android.app.datepickerdialog.<init>(datepickerdialog.java:119) @ android.app.datepickerdialog.<init>(datepickerdialog.java:90) 07-28 10:39:55.253 26562-26562/tvfriends.kolio.com.tvproba e/androidruntime: @ tvfriends.kolio.com.tvproba.activities.hostactivity$datepickerfragment.oncreatedialog(hostactivity.java:311) @ android.support.v4.app.dialogfragment.getlayoutinflater(dialogfragment.java:307) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1104) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1286) @ android.support.v4.app.backstackrecord.run(backstackrecord.java:758) @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1671) @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:532) @ android.os.handler.handlecallback(handler.java:751) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:154) @ android.app.activitythread.main(activitythread.java:6077) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:865) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:755) caused by: org.xmlpull.v1.xmlpullparserexception: binary xml file line #18: <item> tag requires 'drawable' attribute or child tag defining drawable @ android.graphics.drawable.statelistdrawable.inflatechildelements(statelistdrawable.java:183) @ android.graphics.drawable.statelistdrawable.inflate(statelistdrawable.java:116) @ android.graphics.drawable.drawableinflater.inflatefromxml(drawableinflater.java:130) @ android.graphics.drawable.drawable.createfromxmlinner(drawable.java:1224) @ android.graphics.drawable.drawable.createfromxml(drawable.java:1197) @ android.content.res.resourcesimpl.loaddrawableforcookie(resourcesimpl.java:715) ... 34 more
i tried make datepickerdialog separate class showing similar/same error.
initialisation of edittext should trigger datepicker:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.host_activity, container, false); view footer = inflater.inflate(r.layout.footer_host, container, false); init(view, footer); return view; } private void init(view view, view footer) { etdate = (edittext) footer.findviewbyid(r.id.etdate); etdate.setonclicklistener(this); .... }
i suggest use third party lib.because in native datepicker have bug face in api.
compile 'com.wdullaer:materialdatetimepicker:2.4.0'
you can use below :
calendar cal = calendar.getinstance(); int byear = cal.get(calendar.year); int bmonth = cal.get(calendar.month); int bday = cal.get(calendar.day_of_month); com.wdullaer.materialdatetimepicker.date.datepickerdialog dialog= com.wdullaer.materialdatetimepicker.date.datepickerdialog.newinstance(new com.wdullaer.materialdatetimepicker.date.datepickerdialog.ondatesetlistener() { @override public void ondateset(com.wdullaer.materialdatetimepicker.date.datepickerdialog view, int year, int monthofyear, int dayofmonth) { etdob.settext(new stringbuilder().append(dayofmonth) .append("/").append(monthofyear + 1).append("/").append(year)); if (etdob.gettext().tostring().length() == 0) { etdob.seterror("select date"); } else { etdob.seterror(null); } } }, byear, bmonth, bday); dialog.setmaxdate(cal); dialog.show(getactivity().getfragmentmanager(),"datepicker");
if not want use 3rd party lib. can achieve below.:
private void setondateset() { date = new datepickerfragment(); ondate = new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int myear, int monthofyear, int dayofmonth) { etdob.settext(new stringbuilder().append(dayofmonth) .append("/").append(monthofyear + 1).append("/").append(myear)); if (etdob.gettext().tostring().length() == 0) { etdob.seterror("select date"); } else { etdob.seterror(null); } } }; } public class datepickerfragment extends android.app.dialogfragment { datepickerdialog.ondatesetlistener ondateset; int byear, bmonth, bday; public datepickerfragment() { } public void setcallback(datepickerdialog.ondatesetlistener ondate) { ondateset = ondate; } @override public dialog oncreatedialog(bundle savedinstancestate) { calendar cal = calendar.getinstance(); byear = cal.get(calendar.year); bmonth = cal.get(calendar.month); bday = cal.get(calendar.day_of_month); datepickerdialog _date = new datepickerdialog(getactivity(), ondateset, byear, bmonth, bday); _date.getdatepicker().setmaxdate(system.currenttimemillis()); return _date; } }
and can call below on edittext click listner:
setondateset(); // **** set date on button text date.setcallback(ondate); date.show(getactivity().getfragmentmanager(), "datepicker");
define publicly :
private datepickerfragment date; private datepickerdialog.ondatesetlistener ondate;
Comments
Post a Comment