viewBinding
[JETPACK개론] View,DataBinding + Adapter
ViewBinding + Adapter view(Acitivty, Fragment)뿐만 아니라 Adapter에서도 ViewBinding을 사용할 수 있다. 먼저, Adapter를 사용하는 리사이클러뷰를 준비하자! class CustomViewAdapter (private val dataSet : ArrayList) : RecyclerView.Adapter(){ class ViewHolder(binding : TextRowItemBinding) : RecyclerView.ViewHolder(binding.root){ val myText : TextView = binding.myText } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):..
[JETPACK개론] ViewBinding
1. findViewById 위와 같은 xml코드가 있다고 가정해보자. btn1, btn2 가 써져있는 버튼 두개가 생길 것이다. 클래스에서 위의 버튼의 텍스트를 어떻게 변경할까? 맨 처음 생각할 수 있는 것은 findViewById이다. val btn1 : Button = findViewById(R.id.btn1) btn1.text = "abcd" val btn2 : Button = findViewById(R.id.btn2) btn2.text = "abcd" 위의 코드에서는 버튼이 2개라 이 정도로 끝나지만 만일 바꾸고 싶은 버튼이 100개라면 적어도 200줄의 코드를 더 적어야한다. 이렇게 하면 가독성이 떨어지는 문제가 발생한다. 따라서 Kotlin Extensions이 등장했다. gradle파일에 ..