4

我在我的 android 应用程序中使用 Simon 的 ICS 日期选择器库 ( https://github.com/SimonVT )。我有一个日期按钮,如果我单击该按钮,它将在对话框中显示 ics datepicker。我的问题是,如果我单击按钮,它不会显示 datepicker 对话框,但会显示以下错误:

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;
}

在这两种情况下,错误都指向以下行:

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

每个参数都正确传递给 datePickerDialog,但在膨胀对话框中存在问题

任何帮助表示赞赏....

4

3 回答 3

4

我遇到了同样的问题。解决方案是在 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>
于 2013-04-10T15:07:18.973 回答
2

基于@ham 所说的,

将这些行添加为 xml 资源后:

<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>

有必要将此属性添加到您application在 AndroidManifest 中的标签中:

android:theme="@style/SampleTheme"
于 2013-06-26T18:34:33.000 回答
0

也不要错过:

<!-- 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>
-->
于 2015-11-06T22:04:41.923 回答