Saving Data on Android


INTEGER , or  Int  in Kotlin. @ColumnInfo



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

INTEGER
, or 
Int
 in Kotlin.
@ColumnInfo
In the same way that the 
tableName
 property of the 
@Entity
 annotation allows you 
to customize the name of your table, the 
@ColumnInfo
 annotation lets you change 
the name of your columns — class properties in Kotlin:
@Entity
 
data
 
class
 
Movie

    
@PrimaryKey(autogenerate = true)
 
var
 id: 
Int

    
var
 title: String?, 
    
var
 description: String?, 
    
@ColumnInfo(name = "release_date")
 
var
 releaseDate: String?, 
    
var
 rating: 
Float
 
)
Saving Data on Android
Chapter 6: Entity Definitions
raywenderlich.com
109


This annotation is particularly useful because you will often want to follow different 
naming conventions for your class properties and your database columns, such as 
releaseDate
 vs 
release_date
 naming.
@Ignore
Room translates all of your class properties into database columns by default. If 
there is a field that you don't want to be converted into a column, you can use the 
@Ignore
 annotation to tell Room to ignore it:
@Entity
 
data
 
class
 
Movie

    
@PrimaryKey(autogenerate = true)
 
var
 id: 
Int

    
var
 title: String?, 
    
var
 description: String?, 
    
@ColumnInfo(name = "release_date")
 
var
 releaseDate: String?, 
    
var
 rating: 
Float

    
@Ignore
 
var
 poster: Bitmap? 
)
In the above code, you use the 
@Ignore
 annotation to tell Room that you don't want 
the 
poster
 field to be converted as a column in your Movie table. You can also use 
the 
ignoredColumn
 property of the 
@Entity
 annotation to declare which fields you 
want to ignore:
@Entity(ignoredColumns = arrayOf("poster")

data
 
class
 
Movie

    
@PrimaryKey(autogenerate = true)
 
var
 id: 
Int

    
var
 title: String?, 
    
var
 description: String?, 
    
@ColumnInfo(name = "release_date")
 
var
 releaseDate: String?, 
    
var
 rating: 
Float

    
var
 poster: Bitmap? 
)

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   120   121   122   123   124   125   126   127   ...   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