Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 코딩테스트연습
- 월간코드챌린지시즌2
- php
- bootstrap
- 연습문제
- 월간코드챌린지시즌3
- SimpleDateFormat
- androidstudio
- 백준
- bootstrapModal
- 모달
- Fullcalendar
- 스킬체크
- MSSQL
- 안드로이드
- Programmers
- 부트스트랩
- 스킬체크테스트
- Android
- 나머지가1
- 프로그래머스
- AJAX
- Node
- 코딩테스트
- Summer/WinterCoding
- 동적웹페이지
- java
- level1
- REACT
- modal
Archives
- Today
- Total
개발하는 고양이 오이
9. [Android_JAVA] CalendarView 기본값 설정 - calendarView.setDate() 본문
안녕하세요.
안드로이드스튜디오를 이용하다 보면 CalendarView를 이용하는 경우가 많은데요.
보통 CalendarView를 선택했을 때 자동으로 선택되어지는 기본 값은 오늘 날짜입니다.

저는 이 선택되어지는 기본 값이 오늘 날짜가 아닌 다른 날짜(제가 가지고 있는 값)로 선택되어지는 방법을 찾았고, 공유하고자 글을 작성합니다.
CalendarView | Android Developers
CalendarView | Android Developers
android.net.wifi.hotspot2.omadm
developer.android.com
우선 API 문서를 통해 CalendarView에는 setDate() 메소드가 존재하며, setDate는 파라미터가 long형 인것을 알 수 있습니다.
제가 가지고 있는 값은 date형 이었기 때문에 long형으로의 변경이 우선 필요합니다.
// date 를 long 으로 변경 -> 이유 : calendarView.setDate( ) 에 매개변수가 long.
String strDate = dateData.getMeetingDate(); // dateData.getMeetingDate() 는 제가 가지고 있는 Date형 값입니다.
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date currentDay = dateFormat.parse(strDate, new ParsePosition(0));
Long currentLong = currentDay.getTime();
이후, calendarView.setDate()에 변경해준 값을 파라미터에 넣어주면 됩니다.
calendarView.setDate(currentLong);
전체적인 코드는 아래와 같습니다.
String strDate = dateData.getMeetingDate();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date currentDay = dateFormat.parse(strDate, new ParsePosition(0));
Long currentLong = currentDay.getTime();
calendarView.setDate(currentLong);

감사합니다.