Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatePickerDialog incorrectly enforcing a minimum date of Jan 1, 1970

We have a member reporting that he is unable to set a date before Jan 1, 1970 on our DatePickerDialog. This issue does not repro for us.

I am already aware that the DatePickerDialog does not expose the setMinDate/setMaxDate functions of the underlying DatePicker, so it would seem that some kind of handset maker-specific modification is affecting the minDate/maxDate.

This user reports he is running a Droid x2 on Verizon running 2.2 Froyo. While we believe he is correct in his description of his device model, many users are confused about the OS version, so he may be running 2.3.

I attempted to solve this problem by adding this theme to my Activity:

<style name="profile_editor_theme">     
    <item name="android:endYear">2025</item>
    <item name="android:startYear">1910</item>
</style>

While this theme on my activity had the intended effect of constraining the DatePickerDialog on my test devices (a Galaxy tab and an original Motorola Droid), it apparently had no effect for the user.

This issue repros for our user 100% of the time, but works correctly for us on our own devices.

Can anyone explain what might be causing this and how we could fix it?

I have filed this bug against Google on this matter.

Thanks!

like image 983
esilver Avatar asked Dec 23 '11 21:12

esilver


1 Answers

Starting date of Android devices starts from Jan 1, 1970. Maybe this can be your case. Android calculates time as a number of milliseconds passed since Jan 1, 1970.

I've found a kind of hack for your case. Here I create dynamically datePicker:

     DatePicker dp = new DatePicker(this);
     dp.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
     v.addView(dp);

In the manifest file I declare a custom theme for my application - I want the same theme for the application. By the way you can do the same for activity.

 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
    android:theme="@style/CustomTheme">
    <activity
        android:name=".HelloDatePickerActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

In a styles.xml I do this:

<style name="CustomTheme" parent="android:Theme.Light">
    <item name="android:startYear">1890</item>
</style>

The default start date in my case is 1900. Thus, for me this approach works.

Hope this will help you!

like image 73
Yury Avatar answered Oct 25 '22 17:10

Yury