-
Notifications
You must be signed in to change notification settings - Fork 0
Assignment 12 #9
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
base: 실습4
Are you sure you want to change the base?
Conversation
2024 11 19
실습 5
skdud0629
left a comment
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.
수고하셨어요!
|
|
||
| fun submitList(list: List<Word>) { | ||
| wordList = list | ||
| notifyDataSetChanged() |
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.
DiffUtil도 나중에 사용해보시면 좋을 것 같아요! 변경된 부분만 갱신할 수 있어 더 효율적입니당
| private var wordList: List<Word> = emptyList() | ||
|
|
||
| fun addWord(word: Word) { | ||
| val updatedList = wordList.toMutableList() |
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.
MutableList로 변경해준 이유가 뭘까용?
불변성을 유지하기 위해 List 형태 그대로 두는 게 좋아보여용
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_main) | ||
|
|
||
| recyclerView = findViewById(R.id.recyclerView) |
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.
바인딩 써주세요!
| deleteButton.setOnClickListener { | ||
| if(selectedWord != null) { | ||
| Log.d("Test", selectedWord!!.word + " : " + selectedWord!!.definition) | ||
| wordViewModel.removeWord(selectedWord!!) |
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.
!! 연산자는 쓰지 말아주세요. null값이 들어오게 되면 앱이 크래시될 수 있습니다
null일때 예외 처리를 해주세요
2025 02 03
MVVM을 사용하여 만들어보려 하였는데, 잘 안된것 같음.
모델/뷰/뷰모델(AndroidViewModel이 viewmodel에 전역변수 사용할 수 있는 거라고 나와있길래 사용했음.)로 나누어서 코딩하긴 했는데, DataBinding을 못 사용했음.
뷰 모델에서 liveData를 사용해보려 하였지만 에러가 나서 일단 제거하고 일일히 업데이트 하는 식으로 구현함.