我想在列表视图中从Firebase检索嵌套数据,但输出不正确。输出为“ com.example.packagename”。我想在给定位置检索customerName,日期和productName。我还附加了用户模型类。根据我的想法,setkey()方法检索第一个密钥,当前注册用户将其下达的命令与其UID相对,并且内部密钥是从firebase pushkey()方法获得的。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sales_report);
listView = (ListView)findViewById(R.id.listview);
final ArrayAdapter adapter = new ArrayAdapter<UserModel>(this,R.layout.support_simple_spinner_dropdown_item, arrayList);
listView.setAdapter(adapter);
database = FirebaseDatabase.getInstance();
MyRef = database.getReference("placedOrders");
MyRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
UserModel userModel = new UserModel();
for (DataSnapshot dsp : dataSnapshot.getChildren()){
userModel = dsp.getValue(UserModel.class);
userModel.setKey(dsp.getKey());
arrayList.add(userModel);
}
adapter.notifyDataSetChanged();
}
这是我的用户模型类。
public class UserModel {
private String customerName;
private String productName;
private Double latitude;
private Double longitude;
private Date date;
private String key;
public UserModel(){
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
date = date;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
longitude = longitude;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
customerName = customerName;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
productName = productName;
}
}