How can i create a calendar? assigning color to calendar cells. how can i do it

2023-5
2023-4
2023-6
The code I shared in my previous message. It adds color to all the days of my calendar. problem I guess. color codes cycle. Every month is different. did not continue where he left off. The continuation of 2023-05 should be blue on day 1 of 2023-06. but not blue.

The original code selected colors based on position in the list of buttons

You need to change it to base it on day of year for each button.

I have this idea. The user must select the first day. Let the first day start with the background color. Let it continue like this for 15 days. Let the colors turn at the beginning of the 16th day. Let the 16th day be the 1st day. Could there be a different solution?

You can try this.

The selected start date is set at Screen Initialise - you will need to decide how you will select this date in your app.

I use a 360 day cycle (15 day cycle x 24) - so this will need to be updated within the year, or could be extended. This lists the colours required in a text block, which is converted to a list. I then calculate all the dates to a datesList for 360 days from the startDate. The colour for each day from the startdate is then applied in the procedure for showCalendar.

image

calendar_colourDates.aia (11.3 KB)

Thank you. Very kind of you. You did a good job. I have only one problem with the design. In my country the first day of the week is Monday. Sunday is the last day. on sunday i dragged all the buttons and left it to the last day. but it didn't turn out the way I wanted. remained at the bottom. how can I do it
2023-5
2023-6

I can't quite figure out @Kevinkun 's logic in order to switch to Mon - Sun, from Sun - Sat. No doubt Kevin can help at some point.

You have to do this:

The clock component seems to contain the 1st day of the week as Sunday by default.

And move the Sunday label to the end.

timer

Isn't it stored in our phone? By time zone? For example, the name of the day of the week returns according to the language settings. So why does it set Sunday as the first day of the week when it's Monday for me?

1 Like

It is the Clock component instant, which returns the USA format week (Sun-Sat).

Although here: SimpleDateFormat (Java Platform SE 7 )

It lists Mon = 1 Sun = 7....

I see that there is a method for this in the calendar class:
setFirstDayOfWeek()

But I don't see it being used in ai2 sources.

Tracked it down in java.util.Calendar

https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.util.Calendar.SUNDAY

You should see the constant field value for SUNDAY = 1 (in DAY_OF WEEK....)

1 Like

Error when month has 6 rows of weeks. I think it is necessary to add another row of buttons.

1 Like

thanks everyone. You have been very helpful. I solved it manually. I added a new line. And I dragged them one by one. I moved it to the previous button. Problem solved.
okey

I didn't check until October :).

You could have checked it in January too :slight_smile:

Hmmm, I added another row of buttons, named button43 - button54, and added these to the BUTTONS list. I still get the error for Oct and Jan 2023 ?

Select list item: Attempt to get item number 0, of the list [com.google.appinventor.components.runtime.Button.....

I DID IT THIS WAY

calender_son.aia (11.5 KB)

The application was in a way that worked for me. But it works very slow. I have to wait a bit to switch to other settings. The screen is late. Is it related to the color cycle? what is your opinion?

to set Monday as the first day of a week, No need to change the ui (add more buttons), we just to localize the weekday:
image
calendar (1).aia (9.5 KB)
image

to continue the shifting pattern in next month/year, you need a startDate, calculate the duration from startDate to current day, change to days, get modulo (days, length of pattern), pick the right color, set the bg color

4 Likes

Thank you very much. You are great. Do you have a different suggestion regarding the color cycle?

calender.aia (12.8 KB)

Automatic colors do not change when you select a date. I have to close the app and enter it again. When you enter it again, the cell colors change. I want the colors of the cells to change instantly when I select a date. I will be glad if you help

why you use Screen.BackPressed event?

After you set data, have you try to show the calendar again?