Frage

I'll take only two questions related to Android.

I would like to have answered, I'd greatly appreciate it.

1

When you convert to java Calender, why values ​​differ?

ex) year: 1967 month: 12 day: 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);

(Ver. 2.3x)

input: 1967-12-31 00:00 -> result: 1967-12-30 23:30 (X)

input: 1968-10-01 00:00 -> result: 1968-09-30 23:30 (X)

input: 1968-10-02 00:00 -> result: 1968-10-02 00:00 (O)

In version 4.1.2, all values ​​match, there is no problem like that.

(Ver. 4.1.2)

input: 1967-12-31 00:00 -> result: 1967-12-31 00:00 (O)

input: 1968-10-01 00:00 -> result: 1968-10-01 00:00 (O)

input: 1968-10-02 00:00 -> result: 1968-10-02 00:00 (O)

2

When you select (hours or minutes) from the TimePicker*Dialog*, I do not want that the pop-up(keyboard input) is opened.

What should I do now?

I think that I would like you to answer to two questions.

Have a nice day. Thank you.

War es hilfreich?

Lösung

Answer1: Values don't differ in my case, I am using DialogFragment here is my code:

public static class DatePickerFragment extends DialogFragment implements 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 );


    }
}

and this is the result: Year: 2014 ,Month: 1 ,Day: 25

the values are same for three versions of Android, ( 4.1.1, 4.4.2, 2.3.3 ) which I tested.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top