Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet261/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   257   258   259   260   261   262   263   264   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Upda/ng data
Next, you'll add an update feature to your app. You'll see that it's very similiar to 
what you did when adding new data. Open the 
CloudFirestoreManager
 class and 
replace the 
TODO
 inside the 
updatePostContent
with the following:
//1
 
 
val
 updatedPost = HashMap() 
 
 
//2
 
 updatedPost[CONTENT_KEY] = content 
 
//3
 
database.collection(POSTS_COLLECTION) 
  .document(key) 
  .update(updatedPost) 
  .addOnSuccessListener { onSuccessAction() } 
  .addOnFailureListener { onFailureAction() }
1. You start the same way as when adding a new post, by creating a map of data that 
you want to save to the database.
2. When updating an existing document you only need to specify the data that you 
are updating. In this case, this is only the post content.
3. Finally, you get the reference to the posts collection and from there you get the 
reference to the document that you're updating by specifying a key. Then you call 
update
 method on a document reference which updates fields in the document. 
The listener logic stays the same as in the case of writing new data.
Open the 
PostDetailsActivity
 class and inside the 
initializeClickListener
 
function replace the 
TODO
 in the on-click listener, so the 
update post
 button will 
update the database with the update content when clicked:
cloudFirestoreManager.updatePostContent( 
  post.id, 
  postText.text.
toString
().trim(), 
  ::onPostSuccessfullyUpdated, 
  ::onPostUpdateFailed 
)
Now you can update posts in the database as well. You'll be able to test this 
functionality when you implement reading logic in the "Chapter 18: Read data from 
Cloud Firestore".
Saving Data on Android
Chapter 17: Managing Data with Cloud Firestore
raywenderlich.com
256



Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   257   258   259   260   261   262   263   264   ...   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