2017-07-27 76 views
0

我的項目有2個應用程序:Admin-app和Client-app。首先,我需要使用管理員,應用程序,以便將數據放入火力地堡,這裏是我的數據類Firebase中的更新對象字段

public class AllData { 
    private String placeName; 
    private ArrayList<String> category; 
    private String address; 
    private String openingHour; 
    private String website; 
    private HashMap<String, String> review; } 

我用下面的代碼來設置數據進入火力地堡

AllData alldata = new AllData(placeName, category, address, 
        , openingHour, website, null); 
mDatabaseReference = mFirebaseDatabase.getReference().child("Store Data"); 
         DatabaseReference storeData = mDatabaseReference.child(placeName); 
         storeData.setValue(alldata); 

我已經設置在評論欄爲空,因爲我不想讓我的用戶審查客戶的應用程序,並同步其每一個地方到火力地堡的評論欄爲HashMap<UserName, Review>

我使用的客戶應用這些代碼來推動審查,以火力

HashMap<String, String> reviewMap = new HashMap<>(); 
      reviewMap.put(UserName, review); 
      mDatabase = FirebaseDatabase.getInstance(); 
      mReference = mDatabase.getReference().child("Store Data").child(selectedPlace.placeName).child("review"); 
      mReference.push().setValue(reviewMap); 

這不是一個正確的方法,但這就是我所能做到的。我想要的是將用戶的評論更新到異步Firebase中的AllData的評論字段。我怎樣才能做到這一點?每一個答案表示讚賞!

回答

1

您可以簡單地參考直接使用setValue()方法不使用HashMap這樣的:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference(); 
rootRef.child("Store Data").child(selectedPlace.placeName).child("review").setValue(yourValue); 

在這yourValue是要設置的審查鍵的值。

希望它有幫助。

+0

我需要的是在Firebase中設置AllData的評論字段。你的答案提供了與我的結果相同的結果,但以一種縮短的方式感謝 –

+0

比你需要使用偵聽器並直接在dataSnapshot對象上使用'setValue' moethod。 –