Unable to Current Data on Data picker

前端 未结 1 1476
温柔的废话
温柔的废话 2021-01-29 01:10

I Created a Custom Data Picker in which i am showing years from 1950- 2016. now when i first open the picker i want to set current data of the day. but i am not able to set it

1条回答
  •  后悔当初
    2021-01-29 01:56

    I want to set the current date of the day as picker open up for the first time..

    IMO, that's because of the following lines:

    m_calendar.set(Calendar.DAY_OF_MONTH, month);
    m_calendar.set(Calendar.MONTH, day);
    m_calendar.set(Calendar.YEAR, year);
    

    It should be as the following:

    m_calendar.set(Calendar.DAY_OF_MONTH, day);
    m_calendar.set(Calendar.MONTH, month);
    m_calendar.set(Calendar.YEAR, year);
    

    or simply call m_calendar.set(year, month, day);

    Please note that in Calendar.java file:

    public static final int JANUARY = 0;
    public static final int FEBRUARY = 1;
    ...
    

    So if you want FEBRUARY, you should use m_calendar.set(1, month, day); or m_calendar.set(Calendar.FEBRUARY, month, day);. In other words, if you call openDatePicker(3, 20, 2015); the DatePicker will show the date April 20, 2015.

    Hope it helps!

    0 讨论(0)
提交回复
热议问题