티스토리 뷰
View 클래스들을 확장해서 정의할때
생성자 3개인가 다 정의해줘야 되서 구찮았는데 (os버전따라 4개인경우도)
kotlin에선 간단히 한줄로
class CustomTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int = 0)
: TextView(context, attrs, defStyleAttr)
하지만 저렇게 정의하면 xml에서 정의한 style이 안먹는다네?
그래서 style이 먹어줘야하는 view들은 결국 3개다 정의 ㅋ
class CustemTextView : TextView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyle: Int = 0) : super(context, attrs, defStyle)
}
참고로 @JvmOverloads
/**
* Instructs the Kotlin compiler to generate overloads for this function that substitute default parameter values.
*
* If a method has N parameters and M of which have default values, M overloads are generated: the first one
* takes N-1 parameters (all but the last one that takes a default value), the second takes N-2 parameters, and so on.
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
public actual annotation class JvmOverloads
댓글
공지사항
- Total
- 724,015
- Today
- 0
- Yesterday
- 20
링크
TAG
- 노래
- 진해
- 음악
- postcrossing
- 사진
- 일기
- Linux
- 공연
- 일어일기
- 안드로이드
- 아사가야
- 락
- 책
- 드라마
- 코이데 케이스케
- 야마다 타카유키
- 여행
- 잡담
- 영화
- Java
- 서울숲별밤축제
- android
- epik high
- 포스트크로싱
- 도쿄
- 일본
- Mac
- 인디
- 에픽하이
- 신주쿠