Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet100/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   96   97   98   99   100   101   102   103   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Implemen/ng delete
Deleting a record is simple. Open 
ToDoContentProvider.kt
 and copy the following 
code into the body of 
delete
 replacing the 
TODO
 statement:
return
 db.delete(parseLong(selectionArgs?.
get
(
0
)))
This gets the id for the record to delete out of the 
selectionArgs
 and pass that value 
to the database handler to delete the record from the underlying database. The
Saving Data on Android
Chapter 4: ContentProvider
raywenderlich.com
86


number of rows that are deleted is returned.
Next open 
ToDoAdapter.kt
 and add this code to the body of 
deleteToDo
 replacing 
the comment:
// 1
 
selectionArgs = arrayOf(id.toString()) 
// 2
 
context.contentResolver.delete(Uri.parse(queryUri), 
selectionClause, selectionArgs) 
// 3
 
notifyDataSetChanged()
1. Populate 
selectionArgs
 with the id of the record to delete.
2. Run the query to delete the record.
3. Notify the adapter that the dataset has changed so the recyclerview will update.
Run the app, you are now able to delete items from the list. Great! Now you have 
created your very own content provider and content resolver in one. Even though it 
is not required to utilize a content provider when outside apps aren't accessing the 
data, sometimes it can provide an organizational layer of abstraction that can 
improve an app's overall architecture. Now, if you'd like, you can tackle an additional 
challenge and create a client app that will utilize the content provider.

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   96   97   98   99   100   101   102   103   ...   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