Is There A Method Can Be Used To Modify Particular Document In Firestore When User Click On A Card?
Good morning everyone. I have a question here, is there a way that can be used to modify one document in the 'users' collection when the user clicks on a card inside the Android ap
Solution 1:
In order to perform an update, you need to specify the ID of the document you want to update. So you have to pass "pJbM8gfwHiuJUP8R4320" to the document() method and call update() like this:
Map<String, Object> update = newHashMap<>();
update.put("eventDocId", "newID");
DocumentReference docId = collRef.document("pJbM8gfwHiuJUP8R4320");
docId.update("saved_event", update).addOnCompleteListener(newOnCompleteListener<Void>() {
@OverridepublicvoidonComplete(@NonNull@NotNull Task<Void> task) {
Log.d(TAG, "Update complete.");
}
});
Solution 2:
You can attach a listener to every card like so:
// create a CardView and assign a value.CardViewcard_view= (CardView) findViewById(id);
card_view.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
// do whatever you want here
}
});
or you can use a callback:
android:onClick="@{(view) -> callback.onCategoryClick(view, viewModel)}"
I also suggest looking into data-binding: Documentation
Post a Comment for "Is There A Method Can Be Used To Modify Particular Document In Firestore When User Click On A Card?"