0

我将只回答两个与 Android 相关的问题。

我想回答,我将不胜感激。

1

转成java Calender,为什么数值不一样?

ex) 年:1967 月:12 天:31

Calendar calendar = Calendar.getInstance ();
calendar.set (Calendar.YEAR, year);
calendar.set (Calendar.MONTH, (month - 1));
calendar.set (Calendar.DATE, day);
calendar.set (Calendar.HOUR_OF_DAY, 0);
calendar.set (Calendar.MINUTE, 0);
calendar.set (Calendar.SECOND, 0);
calendar.set (Calendar.MILLISECOND, 0);

(版本 2.3x)

输入:1967-12-31 00:00 -> 结果:1967-12-30 23:30 (X)

输入:1968-10-01 00:00 -> 结果:1968-09-30 23:30 (X)

输入:1968-10-02 00:00 -> 结果:1968-10-02 00:00 (O)

在 4.1.2 版本中,所有值都匹配,没有那样的问题。

(版本 4.1.2)

输入:1967-12-31 00:00 -> 结果:1967-12-31 00:00 (O)

输入:1968-10-01 00:00 -> 结果:1968-10-01 00:00 (O)

输入:1968-10-02 00:00 -> 结果:1968-10-02 00:00 (O)

2

当您从 TimePicker* Dialog * 中选择(小时或分钟)时,我不希望打开弹出窗口(键盘输入)。

我现在该怎么办?

我想我希望你回答两个问题。

祝你今天过得愉快。谢谢你。

4

1 回答 1

0

Answer1:在我的情况下,值没有区别,我使用的是DialogFragment 这是我的代码:

公共静态类 DatePickerFragment 扩展 DialogFragment 实现 DatePickerDialog.OnDateSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);

        // Create a new instance of DatePickerDialog and return it
        return new DatePickerDialog(getActivity(), this, year, month, day);
    }

    public void onDateSet(DatePicker view, int year, int month, int day) {
        // Do something with the date chosen by the user

        Log.v(TAG,  "Year: " + year + " ,Month: "+ month + " ,Day: " + day );


    }
}

这是结果:年:2014 年:月:1 日:25

我测试的三个版本的 Android(4.1.1、4.4.2、2.3.3)的值相同。

于 2014-02-25T00:51:50.913 回答