Skip to content

Instantly share code, notes, and snippets.

@griajobag
Created May 9, 2018 14:42
Show Gist options
  • Save griajobag/cfbf53d812bcadb708e536748c71522c to your computer and use it in GitHub Desktop.
Save griajobag/cfbf53d812bcadb708e536748c71522c to your computer and use it in GitHub Desktop.
firestore
private void startInsertDataDocumentManual() {
progressDialog.show();
for (int i = 0; i < 5; i++) {
Map<String, Object> data = new HashMap<>();
data.put("nama", "putuguna " + i);
data.put("website", "putuguna.com " + i);
data.put("temaWeb", "Tentang Programming " +i);
CollectionReference collectionReference = firebaseFirestore.collection("data");
DocumentReference documentReference = collectionReference.document("document"+i);
documentReference.set(data)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Berhasil Insert Data", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Gagal Insert Data", Toast.LENGTH_SHORT).show();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment