반응형
https://blog.naver.com/PostView.nhn?blogId=zion830&logNo=221248961771
override fun onAttach(context: Context) {
super.onAttach(context)
mContext = context
if (context is Activity)
activity = context
}
https://developer.android.com/guide/components/fragments.html?hl=ko
주의: Fragment 내에 Context 객체가 필요한 경우, getContext()를 호출하면 됩니다. 하지만 getContext()를 호출하는 것은 프래그먼트가 액티비티에 첨부되어 있는 경우로 국한해야 한다는 점에 유의하세요. 프래그먼트가 아직 첨부되지 않았거나 수명 주기가 끝날 때 분리되었다면 getContext()는 null을 반환합니다.
반응형
'IT > Android' 카테고리의 다른 글
안드로이드] 네비게이션 바 가림 SYSTEM_UI_FLAG_HIDE_NAVIGATION (0) | 2021.09.03 |
---|---|
Android] viewpager.notifyitemchanged // 다른 페이지는 호출 안 되게 (0) | 2021.09.02 |
Android] 키보드 내리기 (0) | 2021.06.09 |
Android] Kotlin fragment에서 상태표시줄 보여지게 (0) | 2021.06.08 |
Kotlin] 안드로이드 Fragment findViewById Null (0) | 2021.05.22 |
댓글