1) isEmpty보다는 isBlank를 사용하기 (https://lionbae.tistory.com/entry/isEmpty-isBlank)
2) View 객체를 선언하는 부분 관련 코드를 뭉쳐놓기 (코드 이해도와 가독성 향상)
// View 객체 초기화
val imageView: ImageView = findViewById(R.id.sparta)
val textView: TextView = findViewById(R.id.Text1)
val editText1: EditText = findViewById(R.id.editText1)
val textView2: TextView = findViewById(R.id.Text2)
val editText2: EditText = findViewById(R.id.editText2)
val button1: Button = findViewById<Button>(R.id.button1)
val button2: Button = findViewById<Button>(R.id.button2)
// 로직
imageView.setImageResource(R.drawable.sparta)
val id = intent.getStringExtra("id")
val pw = intent.getStringExtra("pw")
editText1.setText(id)
editText2.setText(pw)
3) 변수 선언시 중복된 이름 주의
(코드가 더 방대해졌을 경우에 의도치 않은 오류가 발생할 수 있고 그 오류를 찾아내기가 쉽지 않음)
val id = intent.getStringExtra("id")
val pw = intent.getStringExtra("pw")
button1.setOnClickListener {
val id = editText1.text.toString()
val pw = editText2.text.toString()
}
4) 변수명 더 직관적으로 작성하기 (팀워크에서 매우 중요)
val text1: TextView = findViewById(R.id.name) -> val nameTextView 또는 val tvName
val text2: TextView = findViewById(R.id.wording) -> val wordingTextView 또는 val tvWording
728x90
'앱 개발 > Chapter_Curriculum' 카테고리의 다른 글
[기초 프로젝트] 회고 (0) | 2024.04.08 |
---|---|
Chapter3-2 (앱 개발 기초 프로젝트) (0) | 2024.04.07 |
[과제] Activity 정리 (0) | 2024.03.28 |
[과제] Fragment 정리 (0) | 2024.03.27 |
[과제] UI xml 연습 후기 (0) | 2024.03.26 |