Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView for calendar view

Parts of my old app are deprecated, I am trying to rebuild it. Basically it is a Calendar with month view. This is a part of my gridview adapter:

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();
}

and the int day = date.getDate(); int month = date.getMonth(); int year = date.getYear(); are deprecated. I am trying to use the Calendar class instead of Date but unable to do the same. I know that for retrieve the day, month or year I can use this:

Calendar calendar = Calendar.getInstance();
calendar.get(Calendar.DAY_OF_MONTH); 

but I don't know how to convert this line:

Date date = getItem(position);

for using with Calendar.

like image 292
Dan NoNeed Avatar asked Mar 25 '17 10:03

Dan NoNeed


People also ask

What is a calendar grid?

Grid Calendar is a chart type scheduler for check of multiple schedules at a glance. For plans of private and family, for project of works, for about your favorite sports team, and so on. You can manage schedules that you want to grasp anytime.

What is a grid in Smartsheet?

Views in Smartsheet allow you to see and work with your data in different ways. You can choose between: Grid View—Displays data in a spreadsheet format. Gantt View—Displays data in a spreadsheet on the left and a Gantt chart on the right. Card View—Displays data in cards organized in lanes.

Does Smartsheet have a calendar?

Anyone on a plan with the Calendar App can create and own calendars. Anyone with a Smartsheet account can access a shared calendar. A license is required to create and own a calendar.

Which view must include two date columns in order to be displayed?

In order to use Gantt View, you must have at least two Date columns in your sheet: a start date and an end date.


2 Answers

You can use this line of code:

Just replace this line

Date date = getItem(position);

with this line:

Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();

Here is a full example for you:

Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
int day =  calendar.get(Calendar.DAY_OF_MONTH);
int month =  calendar.get(Calendar.MONTH);
int year =  calendar.get(Calendar.YEAR);
like image 142
AndiM Avatar answered Oct 03 '22 02:10

AndiM


Here is how you convert a Date object to a Calendar object:

Calendar cal = Calendar.getInstance();
cal.setTime(date);

Then (like you said) you can do:

int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH)
int year = cal.get(Calendar.YEAR);
like image 30
aneurinc Avatar answered Oct 03 '22 04:10

aneurinc