# Issues with appearance, month-year and year, for date questions

**URL:** <https://forum.getodk.org/t/issues-with-appearance-month-year-and-year-for-date-questions/4745>\
**Category:** Development\
**Created:** [September 11, 2015, 6:43pm UTC](https://forum.getodk.org/t/issues-with-appearance-month-year-and-year-for-date-questions/4745 "2015-09-11T18:43:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Pringle](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/j/c6cbf5/32.png) [@James\_Pringle](https://forum.getodk.org/u/James_Pringle)\
**Post date:** [September 11, 2015, 6:43pm UTC](https://forum.getodk.org/t/issues-with-appearance-month-year-and-year-for-date-questions/4745/1 "2015-09-11T18:43:55Z")

</div>

I noticed with my clean Google Play version of ODK Collect (1.4.7, 1053), running on Android 5.1.1, that setting appearance::month-year or appearance::year in XLSForm for a date question does not do what it is supposed to. In both cases the app shows working month, date, and year spinners. I found this old issue [https://code.google.com/p/opendatakit/issues/detail?id=873](https://code.google.com/p/opendatakit/issues/detail?id=873), issue 873, and it seems like this issue was supposed to have been fixed. Is there anything I am missing?

Here is my XML on dropbox [https://www.dropbox.com/s/tw0d2df4cwi56iq/dateTimeChooser.xml?dl=0](https://www.dropbox.com/s/tw0d2df4cwi56iq/dateTimeChooser.xml?dl=0)

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [September 13, 2015, 10:44pm UTC](https://forum.getodk.org/t/issues-with-appearance-month-year-and-year-for-date-questions/4745/2 "2015-09-13T22:44:49Z")

</div>

James,

Confirmed as a problem and filed at  
[https://github.com/opendatakit/opendatakit/issues/1169](https://github.com/opendatakit/opendatakit/issues/1169). Code  
contributions welcome.

Yaw

> **···**
>
> -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.
> 
> On Fri, Sep 11, 2015 at 2:43 PM, [jameskpringle@gmail.com](mailto:jameskpringle@gmail.com) wrote:
> 
> > I noticed with my clean Google Play version of ODK Collect (1.4.7, 1053), running on Android 5.1.1, that setting appearance::month-year or appearance::year in XLSForm for a date question does not do what it is supposed to. In both cases the app shows working month, date, and year spinners. I found this old issue [https://code.google.com/p/opendatakit/issues/detail?id=873](https://code.google.com/p/opendatakit/issues/detail?id=873), issue 873, and it seems like this issue was supposed to have been fixed. Is there anything I am missing?
> > 
> > Here is my XML on dropbox [https://www.dropbox.com/s/tw0d2df4cwi56iq/dateTimeChooser.xml?dl=0](https://www.dropbox.com/s/tw0d2df4cwi56iq/dateTimeChooser.xml?dl=0)
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "ODK Developers" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit-developers+unsubscribe@googlegroups.com](mailto:opendatakit-developers+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![James\_Pringle](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/j/c6cbf5/32.png) [@James\_Pringle](https://forum.getodk.org/u/James_Pringle)\
**Post date:** [September 14, 2015, 3:40pm UTC](https://forum.getodk.org/t/issues-with-appearance-month-year-and-year-for-date-questions/4745/3 "2015-09-14T15:40:42Z")

</div>

I will be happy to contribute if only I can find a solution. Here is what I did:

From the current Collect code, I noticed the month and/or day visibility is set by this chunk in DateWidget.java:

> <https://github.com/getodk/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L168-L196>

This looks a lot like a hack because it is bypassing an API and going after the internals of the java class, i.e. if someone on Android decides to refactor the code and rename the class member something other than `mDaySpinner` then Collect's code will no longer work. In fact, it looks like something similar happened.

I am not too certain how to find the real Android source code, but googling led me to this [http://grepcode.com/file\_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0\_r2-robolectric-1/android/widget/DatePicker.java/?v=source](http://grepcode.com/file_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-1/android/widget/DatePicker.java/?v=source). I noticed that the Collect code above only sees `mDelegate`, `LOG_TAG`, `MODE_CALENDAR`, and `MODE_SPINNER` in the enhanced `for` loop. What it needs to do is loop through the member fields of `mDelegate` (according to the Android code I found).

This is where I am getting beyond the bounds of my knowledge and experience. I tried looping through the fields of `mDelegate`. I can get a field that is `mDaySpinner`. However, Field.get(Object) gives my an IllegalArgumentException:

java.lang.IllegalArgumentException: Expected receiver of type android.widget.DatePicker$DatePickerSpinnerDelegate, but got java.lang.Class\<android.widget.DatePicker$DatePickerSpinnerDelegate\>

See

> <https://github.com/jkpr/collect-fixed/blob/dateFix/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L184-L185>

It seems like android.widget.DatePicker$DatePickerSpinnerDelegate is not visible to Collect, so I think I am at a dead end. But I am also not very savvy with this `reflect` package.

Any help on how to move forward would be appreciated.

> **···**
>
> #########################
> 
> Obviously this is a very small piece of ODK Collect, so maybe it is not worth it to try to fix. There are ways around it for survey creators, like single select and integer entry to take place of month and date entry. However, if it is worth it to fix it, then maybe there should be a better solution than using `reflect`. Perhaps Collect should use a custom set of spinners for year and month or just year. It seems like digging around Android source code with `reflect` is not the way to go. Perhaps Dr. Sundt has some thoughts as he was the person to contribute the current code for DateWidget.java?

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [September 15, 2015, 3:26pm UTC](https://forum.getodk.org/t/issues-with-appearance-month-year-and-year-for-date-questions/4745/4 "2015-09-15T15:26:11Z")

</div>

Sounds like reasonable progress, James. Mitch is on vacation but this  
issue has been filed so hopefully he can take a look soon.

And yeah, there are good workarounds, so I'd use those until this gets fixed.

Yaw

> **···**
>
> -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.
> 
> On Mon, Sep 14, 2015 at 11:40 AM, [jameskpringle@gmail.com](mailto:jameskpringle@gmail.com) wrote:
> 
> > I will be happy to contribute if only I can find a solution. Here is what I did:
> > 
> > From the current Collect code, I noticed the month and/or day visibility is set by this chunk in DateWidget.java:
> > 
> > [https://github.com/opendatakit/collect/blob/master/collect\_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L168-L196](https://github.com/opendatakit/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L168-L196)
> > 
> > This looks a lot like a hack because it is bypassing an API and going after the internals of the java class, i.e. if someone on Android decides to refactor the code and rename the class member something other than `mDaySpinner` then Collect's code will no longer work. In fact, it looks like something similar happened.
> > 
> > I am not too certain how to find the real Android source code, but googling led me to this [http://grepcode.com/file\_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0\_r2-robolectric-1/android/widget/DatePicker.java/?v=source](http://grepcode.com/file_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-1/android/widget/DatePicker.java/?v=source). I noticed that the Collect code above only sees `mDelegate`, `LOG_TAG`, `MODE_CALENDAR`, and `MODE_SPINNER` in the enhanced `for` loop. What it needs to do is loop through the member fields of `mDelegate` (according to the Android code I found).
> > 
> > This is where I am getting beyond the bounds of my knowledge and experience. I tried looping through the fields of `mDelegate`. I can get a field that is `mDaySpinner`. However, Field.get(Object) gives my an IllegalArgumentException:
> > 
> > java.lang.IllegalArgumentException: Expected receiver of type android.widget.DatePicker$DatePickerSpinnerDelegate, but got java.lang.Class\<android.widget.DatePicker$DatePickerSpinnerDelegate\>
> > 
> > See  
> > [https://github.com/jkpr/collect-fixed/blob/dateFix/collect\_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L184-L185](https://github.com/jkpr/collect-fixed/blob/dateFix/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L184-L185)
> > 
> > It seems like android.widget.DatePicker$DatePickerSpinnerDelegate is not visible to Collect, so I think I am at a dead end. But I am also not very savvy with this `reflect` package.
> > 
> > Any help on how to move forward would be appreciated.
> > 
> > #########################
> > 
> > Obviously this is a very small piece of ODK Collect, so maybe it is not worth it to try to fix. There are ways around it for survey creators, like single select and integer entry to take place of month and date entry. However, if it is worth it to fix it, then maybe there should be a better solution than using `reflect`. Perhaps Collect should use a custom set of spinners for year and month or just year. It seems like digging around Android source code with `reflect` is not the way to go. Perhaps Dr. Sundt has some thoughts as he was the person to contribute the current code for DateWidget.java?
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "ODK Developers" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit-developers+unsubscribe@googlegroups.com](mailto:opendatakit-developers+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mitch\_S](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Mitch\_S](https://forum.getodk.org/u/Mitch_S)\
**Post date:** [September 22, 2015, 8:15pm UTC](https://forum.getodk.org/t/issues-with-appearance-month-year-and-year-for-date-questions/4745/5 "2015-09-22T20:15:41Z")

</div>

Yes, this is entirely a (necessary) hack.  
If there is a new public API to manage what is displayed, you can do  
something like:

int version = android.os.Build.VERSION.SDK\_INT; if ( version \< ??? ) { //  
existing hack } else { // perhaps use a public API to alter what is  
displayed? } This would allow the code to adjust at runtime based upon the  
Android OS version. From the description, it sounds like the newer Android  
OS and/or SDK has changed this widget and the reflection hack no longer  
works. I would search first for whether there was a way to avoid that via a  
public API before continuing to add layers to this hack.

> **···**
>
> On Tue, Sep 15, 2015 at 8:26 AM, Yaw Anokwa wrote:
> 
> > Sounds like reasonable progress, James. Mitch is on vacation but this  
> > issue has been filed so hopefully he can take a look soon.
> > 
> > And yeah, there are good workarounds, so I'd use those until this gets  
> > fixed.
> > 
> > ## Yaw
> > 
> > Need ODK services? [http://nafundi.com](http://nafundi.com) provides form design, server  
> > setup, professional support, and software development for ODK.
> > 
> > On Mon, Sep 14, 2015 at 11:40 AM, [jameskpringle@gmail.com](mailto:jameskpringle@gmail.com) wrote:
> > 
> > > I will be happy to contribute if only I can find a solution. Here is  
> > > what I did:
> > > 
> > > From the current Collect code, I noticed the month and/or day visibility  
> > > is set by this chunk in DateWidget.java:
> > 
> > [https://github.com/opendatakit/collect/blob/master/collect\_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L168-L196](https://github.com/opendatakit/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L168-L196)
> > 
> > > This looks a lot like a hack because it is bypassing an API and going  
> > > after the internals of the java class, i.e. if someone on Android decides  
> > > to refactor the code and rename the class member something other than  
> > > `mDaySpinner` then Collect's code will no longer work. In fact, it looks  
> > > like something similar happened.
> > > 
> > > I am not too certain how to find the real Android source code, but  
> > > googling led me to this  
> > > [http://grepcode.com/file\_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0\_r2-robolectric-1/android/widget/DatePicker.java/?v=source](http://grepcode.com/file_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-1/android/widget/DatePicker.java/?v=source).  
> > > I noticed that the Collect code above only sees `mDelegate`, `LOG_TAG`,  
> > > `MODE_CALENDAR`, and `MODE_SPINNER` in the enhanced `for` loop. What it  
> > > needs to do is loop through the member fields of `mDelegate` (according to  
> > > the Android code I found).
> > > 
> > > This is where I am getting beyond the bounds of my knowledge and  
> > > experience. I tried looping through the fields of `mDelegate`. I can get a  
> > > field that is `mDaySpinner`. However, Field.get(Object) gives my an  
> > > IllegalArgumentException:
> > > 
> > > java.lang.IllegalArgumentException: Expected receiver of type  
> > > android.widget.DatePicker$DatePickerSpinnerDelegate, but got  
> > > java.lang.Class\<android.widget.DatePicker$DatePickerSpinnerDelegate\>
> > > 
> > > See
> > 
> > [https://github.com/jkpr/collect-fixed/blob/dateFix/collect\_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L184-L185](https://github.com/jkpr/collect-fixed/blob/dateFix/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L184-L185)
> > 
> > > It seems like android.widget.DatePicker$DatePickerSpinnerDelegate is not  
> > > visible to Collect, so I think I am at a dead end. But I am also not very  
> > > savvy with this `reflect` package.
> > > 
> > > Any help on how to move forward would be appreciated.
> > > 
> > > #########################
> > > 
> > > Obviously this is a very small piece of ODK Collect, so maybe it is not  
> > > worth it to try to fix. There are ways around it for survey creators, like  
> > > single select and integer entry to take place of month and date entry.  
> > > However, if it is worth it to fix it, then maybe there should be a better  
> > > solution than using `reflect`. Perhaps Collect should use a custom set of  
> > > spinners for year and month or just year. It seems like digging around  
> > > Android source code with `reflect` is not the way to go. Perhaps Dr. Sundt  
> > > has some thoughts as he was the person to contribute the current code for  
> > > DateWidget.java?
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "ODK Developers" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [opendatakit-developers+unsubscribe@googlegroups.com](mailto:opendatakit-developers+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Developers" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit-developers+unsubscribe@googlegroups.com](mailto:opendatakit-developers+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [August 8, 2018, 5:23pm UTC](https://forum.getodk.org/t/issues-with-appearance-month-year-and-year-for-date-questions/4745/6 "2018-08-08T17:23:05Z")

</div>

A post was split to a new topic: [Click to select specific year](https://forum.getodk.org/t/click-to-select-specific-year/14471)
