#1 Room ์๊ฐ
Room์ ์ฌ์ฉํ์ฌ ๋ก์ปฌ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ฐ์ดํฐ ์ ์ฅ | Android Developers
Room ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ๋ ์ฝ๊ฒ ๋ฐ์ดํฐ๋ฅผ ์ ์งํ๋ ๋ฐฉ๋ฒ ์์๋ณด๊ธฐ
developer.android.com
SQLite๋ ๋ชจ๋ฐ์ผ ๊ธฐ๊ธฐ๋ฅผ ์ํ SQL Database ์์ง์ด๋ค. SQLite๋ ์ ๋ง์ Android ๊ธฐ๊ธฐ์ ํ์ฌ๋์ด์๋ค. ์๋๋ก์ด๋ ๊ฐ๋ฐ์๋ผ๋ฉด SQLite๋ฅผ ์ ๋ค๋ฃฐ ์ ์์ด์ผ ํ๋ค. ํ์ง๋ง, SQLite๋ฅผ ์์ผ๋ก ๋ค๋ฃจ๋ ๊ฒ์ ์ฝ์ง ์๋ค. ๋ฐ๋ณต๋๋ Database Query๋ฌธ ๋ฑ๊ณผ ๊ฐ์ ๋ง์ ์์ฉ๊ตฌ ์ฝ๋๋ฅผ ๋ฐ๋ณต์ ์ผ๋ก ์ ์ด์ฃผ์ด์ผ ํ๊ธฐ ๋๋ฌธ์ด๋ค. ๊ทธ๋ ๊ธฐ์, Database ์์
์ ๋ง์ ์๊ฐ์ด ์์๋๋ค. ์ด์์ ์ธ ๊ทธ๋ฆผ์ด ์๋๋ค. ์ด๋ฐ ๋ฌธ์ ๋ฅผ ๊ฐ์ ํ๊ธฐ ์ํด์, ๊ตฌ๊ธ์ Room Database persistence ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ถ์๋์๋ค.
Room์ ๊ทธ ์์ฒด๊ฐ SQLite๋ฅผ ๊ฐ์ธ๋ ์ถ์ํ ๊ณ์ธต์ด๋ค. ๊ทธ๋ ๊ฒ, SQLite์ ๋ชจ๋ ๊ธฐ๋ฅ์ ๋งค๋๋ฝ๊ฒ ์ฌ์ฉํ๊ธฐ ์ํจ์ด๋ค. Room์ SQLite ์ฌ์ฉ ์ ์ฐจ์ ๋ง์ ๋ถ๋ถ์ ์์์ ์ผ๋ก ์ํํ๊ธฐ์, ์ฝ๋๋์ ์ค์ผ ์ ์๋ค.
Room์ ํ๋ก๊ทธ๋๋จธ๊ฐ ์
๋ ฅํ Annotation์ ์ธ์ํ์ฌ ๋์ํ๋ค. Anonotation์ ๋ฐ๋ผ ์ ์ ํ ๋์์ด ์์์ ์ผ๋ก ์ํ๋๋ ๊ฒ์ด๋ค. Room์ ์ฌ์ฉํ ๋๋ 3๊ฐ์ง ํด๋์ค๊ฐ ์ด์ฉ๋๋ค. ์ฒซ์งธ๋, Database์ ํ
์ด๋ธ์ ๋๋ณํ๋ Entity ํด๋์ค. Annotation์ @Entity๋ค. ๋์งธ๋, Database์ ์ ๊ทผํ๋ ๋ฉ์๋๋ฅผ ๊ตฌํํ๋ DAO(Database Access Object Interface) ํด๋์ค. Annotation์ @Dao๋ค. ์
์งธ๋, ์ค์ SQLite ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋๋ณํ๋ Database ํด๋์ค. Annotation์ @Database๋ค.
#2 Room์ ๊ธฐ๋ณธ์ ๋ด์ ์ํ ์ฑ ๊ฐ์
[Android] MVVM ๊ตฌ์กฐ ํ๋์ ๋ณด๊ธฐ
#1 ์๋๋ก์ด๋ ์ฑ์ '์ ํต์ ์ธ' ๋ฐฉ์ vs MVVM ํจํด #1-1 ๋์๋์ ์ข ์์ฑ ํ์ดํ๋ ํด๋์ค ๊ฐ์ ์ข ์์ฑ์ ๋ํ๋ธ๋ค. ์๋ฅผ ๋ค์ด, View๋ ViewModel์ ์ข ์๋๋ค. ์ข ์์ ์ฌ์ ์ ์๋ฏธ๋ '์์ฃผ์ฑ์ด ์์ด ์ฃผ๊ฐ
kenel.tistory.com
์ ๊ฒ์๊ธ์ #1-3๊ณผ ๊ฐ์ MVVM ํจํด ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๋ ์ํ ์ฑ์ ๋ง๋ค์ด ๋ณธ๋ค. ์ ๊ฒ์๊ธ์ #1-3 ์ฐ์ธก ํ๋จ์ ์๋ Remote Data Source ๋ถ๋ถ์ ๋ณธ ์ํ์์๋ ์ ์ธํ๋ค.
#3 ์ํ ์ฑ ์ ์ - ์์ฑ๋ ์ฑ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
์์ฑ๋ ์ฑ์ ์คํฌ๋ฆฐ์ท์ ๊ฐ์ ธ์๋ค. ์์ ๊ฐ์ ๋ชจ์ต์ด ๋๊ฒ ๋ง๋ค ๊ฒ์ด๋ค. ์๋ซ ๋ถ๋ถ์ ์๋ RecyclerView์ Item์ ํด๋ฆญํ๋ฉด ๋ฒํผ์ Text์ ๊ธฐ๋ฅ์ด ๋ฐ๋๊ฒ ๋ง๋ค ๊ฒ์ด๋ค.
#4 ์ํ ์ฑ ์ ์ - build.gradle.kts (Module) ์์ ํ๊ธฐ
plugins {
...
// kapt (Annotation ์ฝ๊ธฐ)
id("kotlin-kapt")
}
android {
...
// Data binding
buildFeatures {
dataBinding = true
}
}
dependencies {
...
val lifecycleVersion = "2.7.0"
val roomVersion = "2.6.1"
val coroutinesVersion = "1.7.3"
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion")
implementation ("androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion")
// Room
implementation ("androidx.room:room-runtime:$roomVersion")
implementation ("androidx.room:room-ktx:$roomVersion") // ๊ณต์ ๋ฌธ์์์๋ Optional์ด๋ผ๊ณ ๋์ด ์๋ค. ์ค๋ช
์ฐธ์กฐ.
// kapt (Annotation ์ฝ๊ธฐ)
kapt ("androidx.room:room-compiler:$roomVersion")
//Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
}
Data binding, ViewModel, LiveData, Coroutines ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ค. ์ถ๊ฐ๋ก, Annotation ๊ตฌ๋ฌธ์ ์ฝ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ธ kotlin-kapt ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋ฃ๋๋ค. ๋ง์ง๋ง์ผ๋ก, Room ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ ์ถ๊ฐํ๋ค. room-runtime์ ํ์๊ณ , room-ktx๋ ์ ํ์ (Optional)์ผ๋ก implementationํ๋ผ๊ณ ๊ณต์๋ฌธ์์ ๋์ ์๋ค. room-ktx๋ Room์์ ์ฌ์ฉํ ์ ์๋ Coroutines ํด๋์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค. Room์ Background ์ค๋ ๋์์ ๋๋ฆฌ๊ธฐ ์ํด์, Coroutines์ ์ฌ์ฉํ ๊ฒ์ด๋ฏ๋ก ์ถ๊ฐํ๋ค.
#5 ์ํ ์ฑ ์ ์ - Entity, DAO, Database, Repository ํด๋์ค ๊ตฌํ
#5-1 Entity, DAO, Database
[Android] Room - Entity, DAO, Database
#1 ์ด์ ๊ธ https://kenel.tistory.com/120 ๋ณธ ๊ฒ์๊ธ์ Room์ ๊ธฐ๋ณธ์ ๋ด์ ์ฑ์ ๋ง๋ค๊ธฐ ์ํ ์ด์ ๊ฒ์๊ธ์์ ์ด์ด์ง๋ค. ์ฌ๊ธฐ์ Room์ 3๊ฐ์ง ํต์ฌ ํด๋์ค์ธ Entity ํด๋์ค, DAO ํด๋์ค, Database ํด๋์ค์ ๊ตฌํ
kenel.tistory.com
Model์ ํด๋นํ๋, Room์ 3๊ฐ์ง ํต์ฌ ํด๋์ค์ธ Entity ํด๋์ค, DAO ํด๋์ค, Database ํด๋์ค๋ฅผ ๊ตฌํํ๋ค. Room์ ํต์ฌ์ด๊ธฐ ๋๋ฌธ์ ๋ณ๋์ ๊ฒ์๊ธ๋ก ๋บ๋ค.
#5-2 Repository (UserRepository.kt)
// package com.example.roombasics.db
class UserRepository(private val dao: UserDAO) {
val users = dao.getAllUsers()
suspend fun insert(user: User) {
dao.insertUser(user)
}
suspend fun update(user: User) {
dao.updateUser(user)
}
suspend fun delete(user: User) {
dao.deleteUser(user)
}
suspend fun deleteAll() {
dao.deleteAll()
}
}
Repository ํด๋์ค์ ์์ฑ์์ DAO๋ฅผ ๋งค๊ฐ๋ณ์๋ก ๋ฃ๋๋ค. Repository์์ DAO์ ๋ฉ์๋๋ค์ ํธ์ถํ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ด๋ค. dao.getAllUsers()๋ suspend ํค์๋๊ฐ ๋ถ์ง ์์ ํจ์์ด๊ธฐ์ ๊ทธ return๊ฐ์ users๋ผ๋ ํ๋กํผํฐ์ ๋ด์๋ค. suspend ํค์๋๊ฐ ๋ถ์ ํจ์๋ผ๋ฉด ๋ถ๊ฐ๋ฅํ์ ๊ฒ์ด๋ค. (์ฌ๊ธฐ ์ฐธ์กฐ. ์ฌ๋ด์ผ๋ก, ํด๋น ๊ฒ์๊ธ์์ ๋ง๋ insertUser2() ๋ฑ์ ์ผ๋ถ๋ฌ ๊ตฌํํ์ง ์์๋ค.)
#6 ์ํ ์ฑ ์ ์ - Repository, ViewModel, Activity, Data Binding ๊ตฌํ
[Android] MVVM ๊ตฌ์กฐ ํ๋์ ๋ณด๊ธฐ
#1 ์๋๋ก์ด๋ ์ฑ์ '์ ํต์ ์ธ' ๋ฐฉ์ vs MVVM ํจํด ์ ํต์ ์ธ ๋ฐฉ์์์๋ Activity๊ฐ UI ๋ก์ง(ํ๋ฉด ํ์ ๋ฐ ์ฌ์ฉ์ ์ํธ์์ฉ ์ฒ๋ฆฌ)๊ณผ ๋น์ฆ๋์ค ๋ก์ง(๋ฐ์ดํฐ ์ฒ๋ฆฌ, ๋คํธ์ํฌ ํธ์ถ ๋ฑ)์ ๋ชจ๋ ๋ด๋นํ๋ค. ๋ฐ
kenel.tistory.com
์ ๊ฒ์๊ธ์ ๊ธฐ๋ฐํ์ฌ MVVM ํจํด์ ์์ฑํ๋ค.
#6-1 activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12sp"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12sp"
android:ems="10"
android:hint="Name"
android:inputType="text" />
<EditText
android:id="@+id/email_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12sp"
android:ems="10"
android:hint="E-mail"
android:inputType="text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12sp"
android:orientation="horizontal">
<Button
android:id="@+id/save_or_update_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12sp" />
<Button
android:id="@+id/clear_all_or_delete_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/user_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</layout>
๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ์ ์ฌ์ฉํ ๊ฒ์ด๋ฏ๋ก, ์ ์ ์ ์ผ๋ก ์ ์ฒด ์ฝ๋๋ฅผ <layout> ํ๊ทธ๋ก ๊ฐ์๋ค.
#6-2 ViewModel (UserViewModel.kt)
// package com.example.roombasics
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.roombasics.db.User
import com.example.roombasics.db.UserRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class UserViewModel(private val repository: UserRepository) : ViewModel() {
val users = repository.users // ํ์ฌ ์ ์ฅ๋ User๋ค
val inputtedUser = MutableLiveData<User>() // View์ ์
๋ ฅ ๋ฐ์ค์ ๋ฐ์ธ๋ฉ๋ ๊ฐ์ฒด
private var isUpdateOrDelete = false
val saveOrUpdateButtonText = MutableLiveData<String>()
val clearAllOrDeleteButtonText = MutableLiveData<String>()
init {
initSaveAndClearAll()
}
// ์ด๊ธฐํ ๊ด๋ จ
fun initSaveAndClearAll() {
clearInputBox()
renewButtonText()
}
fun initUpdateAndDelete(user: User) {
TODO()
}
// ๋ฒํผ ํด๋ฆญ ์ ๋์
fun saveOrUpdate() {
if (isUpdateOrDelete) {
// Update ์์
TODO()
} else {
// Save ์์
insert(inputtedUser.value!!)
clearInputBox()
}
}
fun clearAllOrDelete() {
if (isUpdateOrDelete) {
// Delete ์์
TODO()
} else {
// Clear All ์์
clearAll()
}
}
// Repository ๋์๊ณผ ๊ด๋ จ๋ ๋ฉ์๋๋ค
fun insert(user: User) = viewModelScope.launch(Dispatchers.IO) {
repository.insert(user)
}
fun update(user: User) = viewModelScope.launch(Dispatchers.IO) {
TODO()
}
fun delete(user: User) = viewModelScope.launch(Dispatchers.IO) {
TODO()
}
fun clearAll() = viewModelScope.launch(Dispatchers.IO) {
repository.deleteAll()
}
// ๊ธฐํ UI ๋ค๋ฌ๊ธฐ์ฉ ๋ฉ์๋๋ค
private fun clearInputBox() {
inputtedUser.value = User(0, "", "")
}
private fun renewButtonText() {
if (isUpdateOrDelete) {
saveOrUpdateButtonText.value = "Update"
clearAllOrDeleteButtonText.value = "Delete"
} else {
saveOrUpdateButtonText.value = "Save"
clearAllOrDeleteButtonText.value = "Clear All"
}
}
}
ViewModel ํด๋์ค์ ์์ฑ์์ Repository๋ฅผ ๋ฃ๋๋ค. Repository๋ ViewModel๊ณผ DAO๋ฅผ ์๋ ์ง๊ฒ๋ค๋ฆฌ ์ญํ ์ ํ๋ค. ์ด๋ฏธ ์ ์ฅ๋ User ๊ฐ์ฒด์ List์ธ users ํ๋กํผํฐ์ View์ ์ค์๊ฐ์ผ๋ก ์ ๋ ฅ๋๋ ์ ๋ณด๋ฅผ ๋ฐ๋ฅด๋ MutableLiveData<Users>()ํ inputtedUser๊ฐ ์๋ก ๊ตฌ๋ถ๋์ด ํ๋กํผํฐ๋ก ์กด์ฌํ๋ค. 2๊ฐ์ ๋ฒํผ์ ๊ฐ๊ฐ 2๊ฐ์ง ์ํฉ์ ๋ฐ๋ผ ๋ค๋ฅธ Text๋ฅผ ํ์ํ๋ค. ๊ทธ ์ํฉ์ isUpdateOrDelete์ true or false๋ก ๋ํ๋ด๋ฉฐ, ์ํฉ์ ์ ํ์ initSaveAndUpdate() ํจ์ ๋๋ initUpdateAndDelete() ํจ์๋ฅผ ํตํด ์งํํ๋ค. ๊ณณ๊ณณ์ ์๋ TODO()๋ ์ด์ด์ง๋ ๊ฒ์๊ธ์์ ๊ตฌํํ๋ค.
#6-3 ViewModelFactory (UserViewModelFactory.kt)
// package com.example.roombasics
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.example.roombasics.db.UserRepository
class UserViewModelFactory(private val repository: UserRepository) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(UserViewModel::class.java)) {
return UserViewModel(repository) as T
}
throw IllegalArgumentException("Unknown ViewModel Class")
}
}
#6-2์ ViewModel์ ๋งค๊ฐ๋ณ์๊ฐ ์กด์ฌํ๋ฏ๋ก, ViewModelFactory๋ฅผ ๋ง๋ค์ด์ฃผ์ด์ผ ํ๋ค.
#6-4 ๋ค์ activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="userViewModel"
type="com.example.roombasics.UserViewModel" />
</data>
<LinearLayout ...>
<EditText
android:id="@+id/name_text"
...
android:text="@={userViewModel.inputtedUser.name}" />
<EditText
android:id="@+id/email_text"
...
android:text="@={userViewModel.inputtedUser.email}" />
<LinearLayout ...>
<Button
android:id="@+id/save_or_update_button"
...
android:onClick="@{() -> userViewModel.saveOrUpdate()}"
android:text="@={userViewModel.saveOrUpdateButtonText}" />
<Button
android:id="@+id/clear_all_or_delete_button"
...
android:onClick="@{() -> userViewModel.clearAllOrDelete()}"
android:text="@={userViewModel.clearAllOrDeleteButtonText}" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView .../>
</LinearLayout>
</layout>
ViewModel์ View(activity_main.xml)์์ ๋ฐ์ ์ฌ์ฉ(๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ)ํ๊ธฐ ์ํด์ #6-1์ ์ฝ๋๋ฅผ ์์ ๊ฐ์ด ์์ ํ๋ค.
#6-5 Activity (MainActivity.kt)
// package com.example.roombasics
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.example.roombasics.databinding.ActivityMainBinding
import com.example.roombasics.db.UserDatabase
import com.example.roombasics.db.UserRepository
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var userViewModel: UserViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
val dao = UserDatabase.getInstance(application).userDAO
val repository = UserRepository(dao)
val factory = UserViewModelFactory(repository)
userViewModel = ViewModelProvider(this, factory)[UserViewModel::class.java]
binding.userViewModel = userViewModel
binding.lifecycleOwner = this
displayUsersList()
}
private fun displayUsersList() {
userViewModel.users.observe(this, Observer {
Log.i("interfacer_han", it.toString())
})
}
}
DAO ์ธ์คํด์ค๋ก Repository ์ธ์คํด์ค๋ฅผ ๋ง๋ ๋ค. ๋ง๋ Repository ์ธ์คํด์ค๋ก ViewModelFactory ์ธ์คํด์ค๋ฅผ ๋ง๋ค๊ณ , ๊ทธ ViewModelFactory ์ธ์คํด์ค๋ก ViewModel ์ธ์คํด์ค๋ฅผ ๋ง๋ ๋ค. ViewModel ์ธ์คํด์ค๋ฅผ activity_main.xml๊ณผ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉํ๊ณ , LiveData์ ๋์์ ์ํด ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ ๊ฐ์ฒด์ LifecycleOwner๋ฅผ ๊ตฌํํ๋ Activity ์๊ธฐ ์์ ๋ ๋๊ฒจ์ค๋ค. ViewModel์ LiveDataํ ํ๋กํผํฐ์ธ Users๋ฅผ LiveData.observe()ํ์ฌ ๊ทธ ๋ณ๋์ฌํญ์ Log ๋ฉ์์ง๋ก ํ์ํ๊ฒ ๋ง๋ ๋ค.
#7 ์๋ ํ์ธ
RecyclerView์ ๊ตฌํ์ด ๋จ์์ง๋ง, ์ง๊ธ๊น์ง ์์ฑํ ์ฑ์ ์๋์ ํ์ธํด๋ณธ๋ค.
#7-1 ์คํฌ๋ฆฐ์ท
#7-2 Log ๋ฉ์์ง
1. ์ด๊ธฐํ๋ฉด []
2. ์ฒซ๋ฒ์งธ User ์ ๋ ฅ ํ Save ๋ฒํผ ํด๋ฆญ [User(id=1, name=Gildong Hong, email=gildong@example.com)]
3. ๋๋ฒ์งธ User ์ ๋ ฅ ํ Save ๋ฒํผ ํด๋ฆญ [User(id=1, name=Gildong Hong, email=gildong@example.com), User(id=2, name=Taewon Han, email=interfacerHan@example.com)]
4. Clear All ๋ฒํผ ํด๋ฆญ []
#8 ์์ฝ
Room์ SQLite์ ์ธ๋ จ๋ ์ฌ์ฉ์ด๋ค.
#9 ์์ฑ๋ ์ฑ
android-practice/room/RoomBasics at master · Kanmanemone/android-practice
Contribute to Kanmanemone/android-practice development by creating an account on GitHub.
github.com
#10 ์ด์ด์ง๋ ๊ธ
[Android] Room - UPDATE ์ฐ์ต
#1 ์ด์ ๊ธ [Android] Room - ๊ธฐ์ด, INSERT์ DELETE ์ฐ์ต #1 Room ์๊ฐ Room์ ์ฌ์ฉํ์ฌ ๋ก์ปฌ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ฐ์ดํฐ ์ ์ฅ | Android Developers Room ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ๋ ์ฝ๊ฒ ๋ฐ์ดํฐ๋ฅผ ์ ์งํ๋ ๋ฐฉ๋ฒ ์์๋ณด
kenel.tistory.com
์ด์ด์ง๋ ๊ธ์์, ๊ฐ Entity๊ฐ ํ๋์ Item์ผ๋ก์ ๋ด๊ฒจ์๋ RecyclerView๊น์ง ๊ตฌํํด๋ณธ๋ค. ์ฌ๊ธฐ์, RecyclerView์ Item์ ํด๋ฆญํ์ฌ ํด๋น Item์ ๋ด๊ธด Entity์ UPDATEํ ์๋ ์๊ฒ ๋ง๋ค์ด๋ณธ๋ค.
'๊นจ์ ๊ฐ๋ ๐ > Android' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android] Room - UPDATE ์ฐ์ต (0) | 2024.02.26 |
---|---|
[Android] Room - Entity, DAO, Database (0) | 2024.02.24 |
[Kotlin] Coroutines - LiveData Builder (0) | 2024.02.22 |
[Kotlin] Coroutines - LifecycleScope (0) | 2024.02.21 |
[Android] RecyclerView - Adapter์ ์ธ์(Argument) ์ ๋ฌ (0) | 2024.02.03 |