Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet95/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   91   92   93   94   95   96   97   98   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Modifying the adapter
To test the content provider you just created, open 
ToDoAdapter.kt
 and add the 
following code inside the class before the 
onCreateViewHolder
 method:
  
private
 
val
 queryUri = CONTENT_URI.toString() 
// base uri
 
  
private
 
val
 queryCountUri = ROW_COUNT_URI.toString() 
  
private
 
val
 projection = arrayOf(CONTENT_PATH) 
//table
 
  
private
 
var
 selectionClause: String? = 
null
 
  
private
 
var
 selectionArgs: Array? = 
null
 
  
private
 
val
 sortOrder = 
"ASC"
Saving Data on Android
Chapter 4: ContentProvider
raywenderlich.com
83


These declarations provide the parameters you will need to pass to the 
contentResolver
 methods to query, update, insert and delete from the database. 
Next you will utilize the content provider by calling the content resolver's functions.
The adapter needs to know how many rows there are to properly configure the 
recyclerview. Locate 
getItemCount
 and insert the code below into the body of the 
function, directly above the 
return
 statement:
// Get the number of records from the Content Resolver
 
val
 cursor = 
context.contentResolver.query(Uri.parse(queryCountUri), 
  projection, selectionClause, 
  selectionArgs,sortOrder) 
// Return the count of records
 
if
(cursor != 
null
) { 
  
if
(cursor.moveToFirst()) { 
    
return
 cursor.getInt(
0

  } 
}
The query above utilizes the query string 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   91   92   93   94   95   96   97   98   ...   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