class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

viewBinding = true

findViewById 는 자바와 꽤나 비슷한 모양새를 가지고 있음

→ 하지만 더이상 지원하지 않는다고 하니...뷰바인딩을 써야할까..

private lateinit var tvContent : TextView

private const val TAG = "ThirdActivity"

class ThirdActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_third)
        
        init()
        initLr()
    }
    
    private fun init(){
        tvContent = findViewById(R.id.tvContent)
    }
    
    private fun initLr(){
        tvContent.setOnClickListener(View.OnClickListener {
            Log.d(TAG, "initLr: 클릭됨")
        })
    }
}

공식문서

Untitled

Untitled

책피셜

MainActivity.kt