gpt4 book ai didi

java - 如何在 Firebase 实时数据库中保存生成的唯一 ID

转载 作者:行者123 更新时间:2023-12-02 01:43:09 32 4
gpt4 key购买 nike

enter image description here大家好,

我期待在 Firebase 实时数据库中保存使用推送方法保存信息时生成的唯一 ID。

下面是我的代码

String bookid = dbreference.child("books").child(condition).push().getKey();

Toast.makeText(getApplicationContext(), "Your question will be uploaded shortly !", Toast.LENGTH_SHORT).show();
b = new Books(btitle, bauthor, bdesc, condition, sellername, selleremail, sellermobile, selleruniversity, bprice,bookid);


dbreference.child("books").child(condition).child(bookid).setValue(b);

它存储来自textview的所有信息,但在bookid中它显示为空,我想存储push key“-LVx3qNb1HCxYKRE5cFl”

我的图书类(class)是

public class Books {
public String bname;
public String bauthor;
public String bdesc;
public String sellername;
public String selleremail;
public String sellermobile;
public String category;
public String selleruniversity;
public String bcondition;
public double price;
public String pics;
public String bookid;
// public Uri uri;

public Books(String bname, String bauthor, String bdesc, String bcondition, String sellername, String selleremail, String sellermobile, String selleruniversity, double price, String bookid) {
this.bname = bname;
this.bauthor = bauthor;
this.bdesc = bdesc;
this.sellername = sellername;
this.selleremail = selleremail;
this.sellermobile = sellermobile;
this.category = category;
this.selleruniversity = selleruniversity;
this.bcondition = bcondition;
this.price = price;
this.pics="";
this.bookid="";
// this.uri = uri;
}

public Books(){}
public String getBname() {
return bname;
}
public String getBauthor() {
return bauthor;
}
public String getBdesc() {
return bdesc;
}
public String getSellername() {
return sellername;
}
public String getSelleremail() {
return selleremail;
}
public String getSellermobile() { return sellermobile;}
public String getCategory() {
return category;
}
public String getSelleruniversity() {
return selleruniversity;
}
public String getCondition() { return bcondition;}
public Double getPrice() {
return price;
}
public String getBookid() {
return bookid;
}
public String getPics() {
return pics;
}
public void setPics(String pics) {
this.pics = pics;
}

}

最佳答案

您的数据库中有 "" ,因为这是您在构造函数中实例化 bookid 字段的方式。要解决此问题,请在您的 Books 类中更改以下代码行:

this.bookid="";

this.bookid = bookid;

关于java - 如何在 Firebase 实时数据库中保存生成的唯一 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54147748/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com