-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
경북대_Android_이혜원 1주차 과제 #3
base: main
Are you sure you want to change the base?
Conversation
viewBinding = true | ||
dataBinding = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
두개의 차이는 무엇이며, 두개를 왜 꼭 같이 써야할까요~?
class ContactViewModel : ViewModel() { | ||
val contactListLiveData = MutableLiveData<MutableList<contact>>().apply { | ||
value = ContactList | ||
} | ||
|
||
fun addContact(contact: contact) { | ||
ContactList.add(contact) | ||
contactListLiveData.value = ContactList | ||
Log.d("ContactViewModel", "Contact added: ${contact.name}, total contacts: ${ContactList.size}") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MVVM은 안쓰기로 하지 않았나요~?
setContentView(binding.root) | ||
|
||
// Intent로부터 데이터를 받아와서 UI에 설정 | ||
val name = intent.getStringExtra("name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보통 이런 요소는 Constant라는 object를 파일단위로 생성하고
const val NAV_KEY_NAME= name" 을 변수로 세팅하여 사용합니다.
그리고 받는쪽에서도 이것을 사용하는거죠.
val phoneNumber = intent.getStringExtra("phoneNumber") ?: "" | ||
|
||
if (name.isNotEmpty() && phoneNumber.isNotEmpty()) { | ||
Log.d("ListActivity", "New contact: $name, $phoneNumber") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드를 업로드하기전엔 로그를 되도록 지워주세요.
val nameEdit: EditText = findViewById(R.id.NameEdit) | ||
val phoneNumberEdit: EditText = findViewById(R.id.PhoneNumberEdit) | ||
val moreText: TextView = findViewById(R.id.MoreText) | ||
val birthEdit: EditText = findViewById(R.id.BirthEdit) | ||
val memoEdit: EditText = findViewById(R.id.MemoEdit) | ||
val genderArea: LinearLayoutCompat = findViewById(R.id.GenderArea) | ||
val saveText: TextView = findViewById(R.id.SaveText) | ||
val cancelText: TextView = findViewById(R.id.CancleText) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메소드를 실행시킬때마다 비싼 xml 파싱을 통해 뷰를 탐색해내는 findViewBy 를 실행하는 것이 아닌,
액티비티가 열렸을때 one-time만 이것들을 호출하여 필드 인스턴스를 할당하고 그것을 계속 재사용하는게 성능측면에서 더 좋아보입니다.
android:layout_weight="3" | ||
android:textAlignment="center" | ||
android:textSize="20dp" | ||
android:text="오른쪽 + 버튼을 클릭하여\n 연락처를 등록해보세요." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String은 추후에 영어등의 다른 언어로 번역해서 쓰일수있으니 strings.xml에서 관리하는게 어떨까요?
val phoneNumber = phoneNumberEdit.text.toString().trim() | ||
|
||
if (name.isEmpty()) { | ||
Toast.makeText(this@MainActivity, "이름은 필수값입니다.", Toast.LENGTH_SHORT).show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 String은 strings.xml
에서 관리하는게 좋아보입니다.
val intent = Intent(this, ListActivity::class.java).apply { | ||
putExtra("name", name) | ||
putExtra("phoneNumber", phoneNumber) | ||
} | ||
startActivity(intent) | ||
finish() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
navigateToContactListView() 이런 함수로 감싸는것도 좋아보이네요.
No description provided.