如何在Firebase数据库中添加Id作为整数?在android中?

时间:2017-04-03 06:39:54

标签: android firebase firebase-realtime-database

我希望Id为整数,不想使用Push.For 例如:

{
   "chats": {
    "1": {
      "title": "Historical Tech Pioneers",
      "messages": {
        "1": { "sender": "ghopper", "message": "Relay malfunction found. Cause: moth." },
        "2": { ... },
     }
    },
    "2": { ... }
  }
}

2 个答案:

答案 0 :(得分:0)

push()方法生成随机密钥,请尝试此

mRef.child("chats").child(your_id).setValue();

答案 1 :(得分:0)

试试这个:

define globe  int i=1;
++i;
databaseReference.child("chats").child(i).setValue();