GridView用于日历视图

Dan*_*eed 5 java android android-gridview calendarview

我的旧应用程序的部分内容已弃用,我正在尝试重建它.基本上它是一个带月视图的日历.这是我的gridview适配器的一部分:

public View getView(int position, View view, ViewGroup parent) {
    Date date = getItem(position);
    int day = date.getDate();
    int month = date.getMonth();
    int year = date.getYear();
}
Run Code Online (Sandbox Code Playgroud)

并且int day = date.getDate(); int month = date.getMonth(); int year = date.getYear(); 已弃用.我正在尝试使用Calendar该类而不是Date无法做同样的事情.我知道,为了检索日,月或年,我可以使用这个:

Calendar calendar = Calendar.getInstance();
calendar.get(Calendar.DAY_OF_MONTH); 
Run Code Online (Sandbox Code Playgroud)

但我不知道如何转换这一行:

Date date = getItem(position);
Run Code Online (Sandbox Code Playgroud)

用于Calendar.

nsc*_*012 1

以下是将Date对象转换为Calendar对象的方法:

Calendar cal = Calendar.getInstance();
cal.setTime(date);
Run Code Online (Sandbox Code Playgroud)

然后(就像你说的)你可以这样做:

int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH)
int year = cal.get(Calendar.YEAR);
Run Code Online (Sandbox Code Playgroud)