Is There A Way To Setresources To Xml File From Firestore?
I find out that the app can get the string array value in XML file via the getResource().getStringArray() method, but is there any way for me to get the string array value from Fi
Solution 1:
Yes, I want to get the array and populate it to my XML resource file as shown above.
You can't and shouldn't be writing data to your XML resource file. If you want to explicitly do it in a file, then you should consider using the external storage on the device.
If you only need to read the data from Firestore to display it in a view, simply use the following lines of code:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference eventRef = rootRef.collection("event");
eventRef.document("8B1shfn8Nwkvh39aRnEK").get().addOnCompleteListener(newOnCompleteListener<DocumentSnapshot>() {
@OverridepublicvoidonComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshotdocument = task.getResult();
if (document.exists()) {
List<String> eventRole = (List<String>) document.get("eventRole");
for (String e : eventRole) {
Log.d("TAG", e);
}
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
The result in the logcat will be:
event leader
event helper
site supervisor
If you need to persist this data across your entire application then you should also consider using SharedPreferences.
Post a Comment for "Is There A Way To Setresources To Xml File From Firestore?"