Simon Ics Date Picker Dialog throws android.view.InflateException: Binary XML file line #20: Error inflating class net.simonvt.widget.DatePicker

若如初见. 提交于 2019-12-05 02:02:54

问题


I'm using Simon's ICS Date Picker Library (https://github.com/SimonVT) in my android app. I have a date button, if I make click on that button, it will show ics datepicker in dialog. My Issue is, if I click on button, it doesn't show datepicker dialog, but it shows following error as :

03-02 10:46:59.521: E/AndroidRuntime(911): android.view.InflateException: Binary XML file line #20: Error inflating class net.simonvt.widget.DatePicker
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-02 10:46:59.521: E/AndroidRuntime(911):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-02 10:46:59.521: E/AndroidRuntime(911):  at net.simonvt.app.DatePickerDialog.<init>(DatePickerDialog.java:103)
03-02 10:46:59.521: E/AndroidRuntime(911):  at net.simonvt.app.DatePickerDialog.<init>(DatePickerDialog.java:74)



@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case START_DATE_PICKER_ID:
            mCalendar.setTimeInMillis(mStartMillis);
            year = mCalendar.get(Calendar.YEAR);
            monthOfYear = mCalendar.get(Calendar.MONTH);
            dayOfMonth = mCalendar.get(Calendar.DAY_OF_MONTH);
            return new DatePickerDialog(ListPillBoxActivity.this, startPillBoxDateListener,
                    year, monthOfYear, dayOfMonth);
        case END_DATE_PICKER_ID:
            mCalendar.setTimeInMillis(mEndMillis);
            year = mCalendar.get(Calendar.YEAR);
            monthOfYear = mCalendar.get(Calendar.MONTH);
            dayOfMonth = mCalendar.get(Calendar.DAY_OF_MONTH);
            return new DatePickerDialog(ListPillBoxActivity.this, endPillBoxDateListener, year,
                    monthOfYear, dayOfMonth);
    }

    return null;
}

Bug pointed towards the following line on both cases :

 return new DatePickerDialog(ListPillBoxActivity.this, startPillBoxDateListener,
                    year, monthOfYear, dayOfMonth);

every parameters is passed correctly to the datePickerDialog, but there is an issue in inflating dialog

Any Help Appreciated....


回答1:


I ran into the same problem. The solution is to add three items to your style like in the DatePickerSamples:

<style name="SampleTheme" parent="@android:style/Theme">
    <item name="calendarViewStyle">@style/Widget.Holo.CalendarView</item>
    <item name="datePickerStyle">@style/Widget.Holo.DatePicker</item>
    <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
</style>



回答2:


Building on what @ham said,

after adding these lines as xml resources:

<style name="SampleTheme" parent="@android:style/Theme">
    <item name="calendarViewStyle">@style/Widget.Holo.CalendarView</item>
    <item name="datePickerStyle">@style/Widget.Holo.DatePicker</item>
    <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
</style>

it is necessary to add this attribute to your application tag in AndroidManifest:

android:theme="@style/SampleTheme"



回答3:


also do not miss :

<!-- Copy one of these attributes to your own theme (choose either dark or light).
    <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
    <item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item>
-->


来源:https://stackoverflow.com/questions/15173687/simon-ics-date-picker-dialog-throws-android-view-inflateexception-binary-xml-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!