DatePicker year list only shows 8 entries in Android

josesjoses Member ✭✭

Hi,

I just got this requirement to let user select dates that could be well in the past. I am using the DatePicker but found out that, in Android, it only shows 8 years to choose from. For example, if I set the date to today and then tap the year at the top the list of years starts at 2016 and ends in 2022. I can tap the earlier one and then re-tap the year, etc but it is not practical if I need to select 1910, for example.

How can I add years to this list?

Thanks

P.S. On iOS the list is not filtered at all.

Tagged:

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited November 2018

    Just a guess... Using Intellisense as a quick and dirty way to see what properties are available. I'm too lazy to look up the class definition right now.

  • josesjoses Member ✭✭

    Thanks, I tried setting both the Min and Max dates but it did not change the list.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Since Xamarin is just a metaphor for the OS controls.... So you're really getting the Android DatePicker... Have you looked at how you would change this behavior if writing a native Android app? Then apply that to the Android project of your solution, either as a CustomRenderer or through the Android manifest... or whatever mechanism corresponds to how you would do it natively?
    https://www.google.com/search?q=android+datepicker+year+range&ie=utf-8&oe=utf-8&client=firefox-b-1-ab

  • josesjoses Member ✭✭

    That is the plan if there isn't an easier solution.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @joses said:
    Hi,

    I just got this requirement to let user select dates that could be well in the past. I am using the DatePicker but found out that, in Android, it only shows 8 years to choose from. For example, if I set the date to today and then tap the year at the top the list of years starts at 2016 and ends in 2022. I can tap the earlier one and then re-tap the year, etc but it is not practical if I need to select 1910, for example.

    How can I add years to this list?

    Thanks

    P.S. On iOS the list is not filtered at all.

    What do you mean by it shows only 8 entries? Isn't the Year picker scrolling up or down? Even just yesterday I used the DatePicker in a project and the year picker scrolls up or down even for default values of Min and Max dates, which I have not set. It may be showing just 8 entries when you tap on the year but you should be able to scroll up or down.

    Yes, I am confused...

  • josesjoses Member ✭✭

    This is what my DatePicker shows:

    (

    I can scroll down to show 2022 but I cannot scroll up further.

  • josesjoses Member ✭✭

    It actually shows 7 years (my arithmetic failed me).

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @joses said:
    It actually shows 7 years (my arithmetic failed me).

    That doesn't matter. Actually I have never tried to set a future date. It will take sometime for me to verify it and think of any solution, if at all it exists.

  • JohnHardmanJohnHardman GBUniversity mod
    edited November 2018

    I've just checked on one of my Android devices and the Xamarin.Forms DatePicker is allowing me to go all the way back to 1900 and all the way forward to 2100. The code is nothing more than:

                DatePicker datePicker = new DatePicker
                {
                    Date = DateTime.UtcNow,
                    TextColor = Color.Black,
                };
    

    @joses - Post your code (C#/XAML)

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Sounds like it might be a behavior difference between versions of Android, or devices.

  • JohnHardmanJohnHardman GBUniversity mod
    edited November 2018

    @ClintStLaurent said:
    Sounds like it might be a behavior difference between versions of Android, or devices.

    I wouldn't rule it out, but it seems strange that a date picker using defaults would let you go back 2 years but no further. I'd want to rule out something in the code, including use of a custom date picker renderer, attempted control over formatting etc.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @JohnHardman
    I guess it depends on what someone thought was "normal use". Credit card expiry date might fall in that window. "First became a member of the loyalty program" date. Certainly not Date Of Birth. Then for the next guy the idea of going back to 1918 for their need is silly.

    So I think it all depends on whomever wrote the defaults.

  • josesjoses Member ✭✭

    @JohnHardman indeed, @ClintStLaurent is right it is device dependent. I get that result in a Zebra TC 25 (rugged device with super duper barcoding, Android 7.1.2) but not on my LG G6 (didn't think to try before). Well, still a problem for me as we target the Zebras. Thanks!

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @joses cc: @JohnHardman
    I personally hate fighting those differences and I prefer to not write renderers if I don't have to. Just a personal preference.
    If it were me - I'd probably stop using the DatePicker since it has proven itself unpredictable and just make my own UI at the agnostic layer so it is always the same on all devices, OSes.
    Maybe just 3 generic Pickers? One for year, one for month, one for day? That way you can send whatever list you like to each. And done.

  • JohnHardmanJohnHardman GBUniversity mod

    Going to charge up some of my less frequently used Android devices to see what they all do, as I do use DatePicker, TimePicker, and a heavily customised one for doing durations. Haven't spotted a problem previously, but no harm in checking again...

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @joses I tested in Note 9, iPhone 6 and on my PC (UWP). In all three the upper limit is 2100 as @JohnHardman said.

    Is your XAML also same as what @JohnHardman mentioned above? If not, post the code.

  • josesjoses Member ✭✭

    @ShantimohanElchuri I created a brand new Xamarin Forms project with just:

    <StackLayout>
        <DatePicker/>
    </StackLayout>
    

    And I get the same results (the year list only shows 2016 to 2022).

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @joses said:
    @ShantimohanElchuri I created a brand new Xamarin Forms project with just:

    <StackLayout>
        <DatePicker/>
    </StackLayout>
    

    And I get the same results (the year list only shows 2016 to 2022).

    That is really bad. I suppose now you should get professional help. Why don't ;you try the Microsoft Xamarin Support link at the top of this forum?

  • josesjoses Member ✭✭

    Yes. I asked Zebra since it is them who package the whole thing.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Huh? Zebra packages Xamarin Forms? Can you shed some like on what that last statement means?

  • JohnHardmanJohnHardman GBUniversity mod

    It sounds like Zebra might have tweaked the Android implementation. If that's the case, it would be useful to know (a) if they have an API that allows the date range to be changed, and (b) the most reliable method of identifying that an app is running on a device or o/s version that needs to do extra effort to get the desired range.

  • josesjoses Member ✭✭

    @ClintStLaurent : no, they sell the phone with Android plus some software and hardware, not Xamarin forms, but their forum has a lot of movement on Xamarin forms so maybe I will get lucky. Maybe they tweaked Android as John says. It is easy to identify the phone with the device plugin. It is identified by the name "ZEBRA TECHNOLOGIES TC25".

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited November 2018

    I guess I got lost. I thought you posted that you made a brand new generic "Welcome to Xamarin" solution and it did the same thing. So doesn't that indicate that the Zebra stuff has nothing to do with this? What am I missing?

Sign In or Register to comment.