Room + ListAdapter + ViewModel 등을 함께 이용해서 CRUD 앱을 만들어보겠습니다.
아래와 같은 앱을 만들어보겠습니다.
random number를 생성하여 업데이트 삭제를 할 수 있는 앱입니다.

This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context=".MainActivity"> | |
<Button | |
android:id="@+id/create" | |
android:layout_margin="10dp" | |
android:text="create random number" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/numberRV" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"/> | |
</LinearLayout> |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="100dp"> | |
<TextView | |
android:id="@+id/id" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_margin="20dp" | |
android:gravity="center" | |
android:text="id" | |
android:textSize="15sp"/> | |
<TextView | |
android:id="@+id/randomNum" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_margin="20dp" | |
android:gravity="center" | |
android:text="randomNum" | |
android:textSize="15sp"/> | |
<Button | |
android:id="@+id/update" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_margin="10dp" | |
android:text="update"/> | |
<Button | |
android:id="@+id/delete" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_margin="10dp" | |
android:text="delete"/> | |
</LinearLayout> |
'Android Jetpack' 카테고리의 다른 글
Room Advanced - 3 (구조) (0) | 2023.02.02 |
---|---|
Room Advanced - 2 (DB) (0) | 2023.02.02 |
ROOM + Coroutine Flow - 7 (Room + Flow + ListAdapter CRUD) (0) | 2023.01.29 |
ROOM + Coroutine Flow - 6 (Room + Flow + ListAdapter) (0) | 2023.01.28 |
ROOM + Coroutine Flow - 4 (Why Room & Coroutine - 2) (0) | 2023.01.28 |