0
我只是不知道如何設置根ID與我自己的而不是被頂部while循環中產生的推送()鍵的鍵..根ID的火力地堡設定鍵
-Waypoint
-RootID <-- This key
-Points
....................
LinkedHashMap<String, Object> pointHolder = new LinkedHashMap<>();
LinkedHashMap<String, Object> waypointHolder = new LinkedHashMap<>();
waypointsUrl = Constants.FIREBASE_URL + "https://stackoverflow.com/users/" + mUserId + "/waypoints";
mainRef = new Firebase(waypointsUrl);
.................
更新代碼
while (isFirstTime) {
// Generates root id for date
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
mLastUpdateTime = dateFormat.format(date);
// Generates root id
mainRefKey = mainRef.push();
isFirstTime = false;
}
// Generates new id for point
Firebase wayRef1 = mainRefKey.push();
String pointKey = wayRef1.getKey();
// Create Waypoint > Point > put lat and lon
LinkedHashMap<String, Object> latLng = new LinkedHashMap<String, Object>();
latLng.put("latitude", 123);
latLng.put("longitude", 123);
// Puts lat and lon ** under a Point Key **
pointHolder.put(pointKey, latLng);
// Waypoint > POINT (contains multiple points)
waypointHolder.put("points", pointHolder);
waypointHolder.put("timeStamp", "24/3-2016");
waypointHolder.put("travelType", "travel");
// ROOT ID > Waypoint
mainRefKey.updateChildren(waypointHolder);
}
});
圖片所需的結構:
沒有按沒有工作。什麼是某些你想要的。猜猜它是根id,但是當前的id是什麼? –
這樣做是爲了讓它工作:'mainRef.child(mLastUpdateTime).setValue(waypointHolder);'在底部。 –
我現在看到,它添加了一個推按鍵和我自己的按鍵,按下的按鍵總是相同的並被覆蓋 –