我有一個像這樣的 Firestore 數(shù)據(jù)庫:我想訪問每個不同的癥狀數(shù)據(jù),即“Anxiety_data”及其由時間戳組成的子項,然后是字典,并將它們放入RecyclerView使用中FirebaseUI FirebaseRecyclerViewAdapter我有這個模型類: public class EntryDataModel {private String timestamp, symptom, severity, comment;public EntryDataModel() {}public EntryDataModel(String timestamp, String symptom, String severity, String comment) { this.timestamp = timestamp; this.symptom = symptom; this.severity = severity; this.comment = comment;}public String getTimestamp() {return timestamp;}public String getSymptom() {return symptom;}public String getSeverity() {return severity;}public String getComment() {return comment;}}這是我的Query:Query query = db.collection("users").document(user_id).collection("symptom_data");這是Firebase RecyclerView Adapter:void fireStoreRecyclerAdapterSetup() { FirestoreRecyclerOptions<EntryDataModel> options = new FirestoreRecyclerOptions.Builder<EntryDataModel>() .setQuery(query, EntryDataModel.class) .build(); FirestoreRecyclerAdapter adapter = new FirestoreRecyclerAdapter<EntryDataModel, EntryDataHolder>(options) { @Override public void onBindViewHolder(EntryDataHolder holder, int position, EntryDataModel model) { // Bind the Chat object to the ChatHolder // ... System.out.println("Query: " + query.toString()); } }}我不確定我應該如何設置它,以便我從每個癥狀數(shù)據(jù)字段中獲取所有時間戳數(shù)組,并將它們?nèi)糠旁谝粋€列表中,我可以將其用于recyclerView.也許我不能使用 FirebaseUI Recycler 適配器,或者我需要先遍歷每個不同的癥狀字段并構(gòu)建 + 附加一個列表?希望我清楚我想做什么謝謝。
1 回答

隔江千里
TA貢獻1906條經(jīng)驗 獲得超10個贊
Firebase SDK 可以執(zhí)行的從 Firestore 文檔到 Java 對象的自動映射要求文檔中的每個字段名稱與 Java 類中的屬性名稱相匹配。它沒有處理動態(tài)字段的機制,例如您示例中的時間戳。
所以你必須自己進行轉(zhuǎn)換。為此,您可以使用public T get (FieldPath fieldPath, Class<T> valueType)
orpublic T get (String field, Class<T> valueType)
方法,它允許您從指定的特定字段中獲取對象。因此,您必須遍歷時間戳字段,但之后 Firebase SDK 可以將severity
、symptom
和timestamp
屬性映射到對象。
添加回答
舉報
0/150
提交
取消