Open
Conversation
2024 11 19
실습 5
skdud0629
reviewed
Feb 4, 2025
|
|
||
| fun submitList(list: List<Word>) { | ||
| wordList = list | ||
| notifyDataSetChanged() |
There was a problem hiding this comment.
DiffUtil도 나중에 사용해보시면 좋을 것 같아요! 변경된 부분만 갱신할 수 있어 더 효율적입니당
| private var wordList: List<Word> = emptyList() | ||
|
|
||
| fun addWord(word: Word) { | ||
| val updatedList = wordList.toMutableList() |
There was a problem hiding this comment.
MutableList로 변경해준 이유가 뭘까용?
불변성을 유지하기 위해 List 형태 그대로 두는 게 좋아보여용
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_main) | ||
|
|
||
| recyclerView = findViewById(R.id.recyclerView) |
| deleteButton.setOnClickListener { | ||
| if(selectedWord != null) { | ||
| Log.d("Test", selectedWord!!.word + " : " + selectedWord!!.definition) | ||
| wordViewModel.removeWord(selectedWord!!) |
There was a problem hiding this comment.
!! 연산자는 쓰지 말아주세요. null값이 들어오게 되면 앱이 크래시될 수 있습니다
null일때 예외 처리를 해주세요
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
2025 02 03
MVVM을 사용하여 만들어보려 하였는데, 잘 안된것 같음.
모델/뷰/뷰모델(AndroidViewModel이 viewmodel에 전역변수 사용할 수 있는 거라고 나와있길래 사용했음.)로 나누어서 코딩하긴 했는데, DataBinding을 못 사용했음.
뷰 모델에서 liveData를 사용해보려 하였지만 에러가 나서 일단 제거하고 일일히 업데이트 하는 식으로 구현함.