안드로이드 개발 질문/답변
(글 수 45,052)
private int mStartPos;
private int mEndPos;
private int mDaysInMonth;
public void setBaseDate(Calendar cal)
{
mBaseDate = (Calendar) cal.clone();
Calendar lastDayInMonth = (Calendar) cal.clone();
lastDayInMonth.add(Calendar.MONTH, 1);
lastDayInMonth.add(Calendar.DATE, -1);
mDaysInMonth = lastDayInMonth.get(Calendar.DATE);
mStartPos = 7 + mBaseDate.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY;
mEndPos = mStartPos
+ mDaysInMonth //
+ (int) ((mStartPos - 9 + mDaysInMonth) / 7)
-1;
}
달력 위치값 설정해주는 부분인데요;
mDaysInmonth 에 무슨값이 들어가는지 모르겠습니다;
그리고 mEndPos 를 왜 저런식으로 구하는지 알려주시면 감사합니다. ㅠ




소스 만드신분에게 정말 감사하는 마음으로 ....
mDaysInMonth에 들어가는 값은
이클래서 처음 들어가기전에 현재달 1일로 초기화해서 달력을 구성해 놓지요
lastDayInMonth.add(Calendar.MONTH, 1); 여기서 현재 달에서 다음달로 달력을 바꿉니다
lastDayInMonth.add(Calendar.DATE, -1); 여기서 하루를 빼면 이전달 마지막일이 되겠지요??
mDaysInMonth 그러니까 현재달의 요일수가 들어가는 겁니다
이걸 쉽게 구하면 mDaysIntMonth = mBaseDate.getActualMaximum(Calendar.DAY_OF_MONTH);로 변경하시면 됩니다..
mEndPos는 저 7로 나눠주는 부분은 그달에 몇주까지 있는지 계산하여 주를표시하여 주는 셀갯수를 추가해주기 위해서입니다.
그리고 끝에-1은 밑에position은 0부터 시작하기 때문에 1을 빼주는 겁니다.....아마도..ㅡㅡ;;