Saving Data on Android


model  package and name it  Answer



Download 19,28 Mb.
Pdf ko'rish
bet129/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   125   126   127   128   129   130   131   132   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

model
 package and name it 
Answer
.
Once again, fill or replace the file content with the following code:
@Entity(tableName = "answers")
 
data
 
class
 
Answer

    
@PrimaryKey(autoGenerate = true)
 
    
@ColumnInfo(name = "answer_id")
 
    
val
 answerId: 
Int

    
@ColumnInfo(name = "question_id")
Saving Data on Android
Chapter 6: Entity Definitions
raywenderlich.com
114


    
val
 questionId: 
Int

    
@ColumnInfo(name = "is_correct")
 
    
val
 isCorrect: 
Boolean

    
val
 text: String 
)
The code is very similar to the 
Question
 class, so there is not much need to explain 
the steps. With this, your entities are ready, and it is time to create your database!
Create a new package under the data directory and name it 
db
.
Now, create a new class under the 
db
 package and name it 
QuizDatabase
. Replace 
everything inside with the following:
@Database(entities = [(Question::class)
, (Answer::
class
)], 
version = 1)
 
abstract
 
class
 
QuizDatabase
 : 
RoomDatabase
()
Similar to your entities, Room uses the 
@Database
 annotation to define which class 
should be used to generate your database tables, connections and queries.
The 
@Database
 annotation should always include at least two properties:

entities
: These should include an array of all the the entities associated with 
your database.

version
: This is the current version of your database, which is used to migrate 
everything once things change.
Note
: It is very important that you declare your class as an abstract class that 
extends from 
RoomDatabase
 or Room will throw an error.
There are many ways to get an instance of your database at runtime, but, for this 
app, you will create a property inside your 
Application
 class.
Create a new class under the root package of your project — 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   125   126   127   128   129   130   131   132   ...   292




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish