DatePickerDialog错误地执行了1970年1月1日的最低日期 [英] DatePickerDialog incorrectly enforcing a minimum date of Jan 1, 1970

查看:153
本文介绍了DatePickerDialog错误地执行了1970年1月1日的最低日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个会员报告说,他无法在1970年1月1日之前在DatePickerDialog上设置日期。这个问题对我们来说是无效的。



我已经意识到DatePickerDialog不会暴露基础的DatePicker的setMinDate / setMaxDate函数,所以看起来有点像手机制造商特定的修改影响了minDate / maxDate。



该用户报告他在Verizon上运行了一个运行2.2 Froyo的Droid x2。虽然我们相信他对他的设备型号的描述是正确的,但许多用户对操作系统版本感到困惑,所以他可能正在运行2.3。



我试图解决这个问题将此主题添加到我的活动中的问题:

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

虽然我的活动中的这个主题有预期的效果,限制我的测试设备上的DatePickerDialog标签和原始的摩托罗拉Droid),这显然对用户没有影响。



此问题在100%的时间内为我们的用户重新定位,但在我们自己的设备上正常工作。



任何人都可以解释可能导致这种情况,以及我们如何解决它?



我有向Google提交了这个错误



谢谢!

解决方案

从1970年1月1日起,Android设备的开始日期开始。也许这可能是你的情况。 Android计算时间是从1970年1月1日起经过的毫秒数。



我发现了一种黑客。
这里我创建动态的datePicker:

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

在清单文件中,我为我的应用程序声明一个自定义主题 - 我想要应用程序的相同主题。你可以做同样的活动。

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

在styles.xml中,我执行以下操作:

 < style name =CustomThemeparent =android:Theme.Light> 
< item name =android:startYear> 1890< / item>
< / style>

我的情况下的默认开始日期是1900.因此,对于我来说,这种方法是有效的。 >

希望这将有助于您!


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!

解决方案

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!

这篇关于DatePickerDialog错误地执行了1970年1月1日的最低日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆