View Binding을 사용해 setOnClickListener를 이용해 버튼이 클릭되면 특정이벤트를 수행하는 동작을 만들던 도중
setOnClickListener안에서 변수를 디버깅하는데 this@액티비티명 is not caputred라고 나와서 디버깅에 한참 애를 먹었다.
아래 게시글에 따르면 코틀린에서는 setOnClickListener를 람다형식으로 하면 디버깅을 할수없다고 한다.
https://stackoverflow.com/questions/67873951/thisactivityname-is-not-captured-error-android-kotlin
'this@ActivityName' is not captured error Android/Kotlin
I'm repairing my friend's code and got confused. My friend wants to fetch entered text (in EditText). Seems easy, right? Well, it is but instead of user input, he gets this warning/error: To be ho...
stackoverflow.com
binding.button.setOnClickListener(){ // 변수디버깅 불가능
// somethingTodo()
}
아마, 변수가 디버깅이 안된다면 위와같은 형식으로 만들었을텐데 아래와 같은 형식으로 만들어야 디버깅을 할수 있다.
binding.button.setOnClickListener(object : View.OnClickListener { // 변수 디버깅 가능
override fun onClick(p0: View?) {
// somethingTodo()
}
})
'프로그래밍 > Android' 카테고리의 다른 글
[Android] Splash 사용법과 사용이유 (0) | 2022.07.10 |
---|---|
[Android] 라디오버튼, 체크박스가 클릭안되는 현상 (0) | 2022.07.10 |
[Android] 코드로 margin값 주기 (0) | 2022.05.20 |
[Android] toUpperCase() 경고메시지 (0) | 2022.05.03 |
[Toast] 위치조절 (0) | 2022.05.03 |
댓글