Saving Data on Android


model  package by right-clicking on  model



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

model
 package by right-clicking on 
model
 and 
selecting 
New 

 Kotlin File/Class
, and name it 
Question
.
Fill or replace the file content with the following code:
@Entity(tableName = "questions")
 
// 1
 
data
 
class
 
Question

    
@PrimaryKey(autoGenerate = true)
 
// 2
 
    
@ColumnInfo(name = "question_id")
 
// 3
 
    
var
 questionId: 
Int

    
val
 text: String 
)
Note
: Remember to use 
Alt
 + 
Enter
 on PC or 
Option
 + 
Return/Enter
 on a 
Mac to import any missing dependencies.
The code does the following, step by step:
1. The 
@Entity
 annotation tells Room that this data class should be converted into 
an entity. The 
tableName
 property indicates that the table name should be 
questions
.
2.
@PrimaryKey
 makes the 
questionId
 field of your 
Question
 class a primary key 
of the table. The 
autogenerate
 property declares that Room will generate the 
primary key for you as an auto-incremented integer.
3.
@ColumnInfo
 allows you to customize your column's properties like the name or 
the type affinity - 
Integer

Text

Float
, etc.
Now, create another class under the 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   124   125   126   127   128   129   130   131   ...   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