亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何處理我的數據模型類以將 Firebase Firestore 數據放入

如何處理我的數據模型類以將 Firebase Firestore 數據放入

一只斗牛犬 2022-12-15 11:21:21
我有一個像這樣的 Firestore 數據庫:我想訪問每個不同的癥狀數據,即“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());        }       }}我不確定我應該如何設置它,以便我從每個癥狀數據字段中獲取所有時間戳數組,并將它們全部放在一個列表中,我可以將其用于recyclerView.也許我不能使用 FirebaseUI Recycler 適配器,或者我需要先遍歷每個不同的癥狀字段并構建 + 附加一個列表?希望我清楚我想做什么謝謝。
查看完整描述

1 回答

?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

Firebase SDK 可以執行的從 Firestore 文檔到 Java 對象的自動映射要求文檔中的每個字段名稱與 Java 類中的屬性名稱相匹配。它沒有處理動態字段的機制,例如您示例中的時間戳。

所以你必須自己進行轉換。為此,您可以使用public T get (FieldPath fieldPath, Class<T> valueType)orpublic T get (String field, Class<T> valueType)方法,它允許您從指定的特定字段中獲取對象。因此,您必須遍歷時間戳字段,但之后 Firebase SDK 可以將severity、symptomtimestamp屬性映射到對象。


查看完整回答
反對 回復 2022-12-15
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號