look at the documentation of Calendar.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
look again... You'll notice you can get the day as a number.
An array is indexed on a number.
Put 2 and 2 together and you'll have insight.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Thendral, in my opinion you are complicating your work. Why not to have 7 images in array and then you have no need for additional calculations. Just find out which day of week is currently and call array position to retrive image.
If you still feel funky then you can setup 31 images and acording to day in the month you call relevant image. Then you have image for each day
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
How about something like:
imageId = imageArray.length % dayOfMonth;
Change the formula to suit your needs but I hope you get the logic right.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
The usual "this doesn't work" is not helpful at all. You need to tell us 'what' is not working and what you have tried out. Post the most recent relevant code which shows the concerned logic and then we can work out something.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Why doesn't this work in your case:
dayCount = (dayOfMonth - 1) % arraySize;
imageId = myImageArray[dayCount];
Oh and BTW, your logic is wrong, the array indexing starts at 0 and not at 1. So your mesh of 'if' statements which use 1 as the starting index is wrong, unless you have something different planned out.
Plus you are using the wrong method to get the day. You should get the day of month, not the day of week otherwise you would always access the first 7 images since DAY_OF_WEEK ranges between 1 to 7. Use this:
GregorianCalendar c = new GregorianCalendar();
int day = c.get(Calendar.DAY_OF_MONTH);
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734