Saving Data on Android


Question.kt  under the  data



Download 19,28 Mb.
Pdf ko'rish
bet184/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   180   181   182   183   184   185   186   187   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Question.kt
 under the 
data 

 model
 package. Right now, your entity looks 
like this:
@Entity(tableName = "question", indices = 
[Index("question_id")
]) 
data
 
class
 
Question

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

  
val
 text: String 
)
You want to represent the difficulty in terms of numbers such as 1, 2 or 3, where 1 is 
the lowest difficulty and 3 is the highest. To represent this concept, modify your 
question class to add a 
difficulty
 property like so:
@Entity(tableName = "question", indices = 
[Index("question_id")
]) 
data
 
class
 
Question

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

  
val
 text: String, 
  
val
 difficulty: 
Int
 = 
0
 
//Only this lane changes
 
)
This property will represent the difficulty of the question and will have a default 
value of 0.
Saving Data on Android
Chapter 10: Migrations with Room
raywenderlich.com
175


Now, build and run the app and press the 
Start
 button to see if it works.
And the app crashed!
Open the logcat console and take a look at the error displayed:

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   180   181   182   183   184   185   186   187   ...   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