Skip to content

Conversation

@jusang3057
Copy link
Owner

@jusang3057 jusang3057 commented Feb 3, 2025

2025 02 03
MVVM을 사용하여 만들어보려 하였는데, 잘 안된것 같음.
모델/뷰/뷰모델(AndroidViewModel이 viewmodel에 전역변수 사용할 수 있는 거라고 나와있길래 사용했음.)로 나누어서 코딩하긴 했는데, DataBinding을 못 사용했음.
뷰 모델에서 liveData를 사용해보려 하였지만 에러가 나서 일단 제거하고 일일히 업데이트 하는 식으로 구현함.

2024 11 19
실습5
2024-12-02
202024-12-02
2024 12 23
2024 12 23
2024 12 30
2025 01 06
2025 01 13
2025 01 20
2025 01 20
2025-02-03
Copy link

@skdud0629 skdud0629 left a 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()

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()

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)

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!!)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! 연산자는 쓰지 말아주세요. null값이 들어오게 되면 앱이 크래시될 수 있습니다
null일때 예외 처리를 해주세요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants