如何从Firebase Cloud Firestore获取数据作为模型? 您能告诉我完整的代码吗? 非常感谢。
型号:
public class Vehicle implements Serializable {
private String Title;
private int Year;
private int Price;
private String City;
public Vehicle(String title, String city, int price, int year) {
Title = title;
City = city;
Price = price;
Year = year;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public int getYear() {
return Year;
}
public void setYear(int year) {
Year = year;
}
public int getPrice() {
return Price;
}
public void setPrice(int price) {
Price = price;
}
public String getCity() {
return City;
}
public void setCity(String city) {
City = city;
}
}
MainActivity:
从文档中获取代码,但无法获得车辆标题
DocumentReference docRef = db.collection("cities").document("SF");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
Log.d(TAG, "DocumentSnapshot data: " + document.getData());
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
能否请您向我展示代码,例如如何以字符串形式获取标题等等,我必须在回收站视图中显示它,因此我必须从firebase中设置setTitle,从模型中获取getTitle