Hallo, ich bin ein Neuling auf Firebase .Dies ist, wie meine DatenAbrufen von Daten aus verschachtelten Objekten Firebase mit Android/Java?
wie aussehen würde ich gerne wissen, wie ich die distributorInfo abrufen kann von retailers.I distributorInfo aus einem FirebaseRecyclerAdapter des populateViewHolder method.I Uhr abrufen versuchte kann den Schlüssel für das ausgewählte Element abrufen. Wie bekomme ich die Informationen in distributorInfo?
private void getRetailers() {
FirebaseRecyclerAdapter<RetailerInfo,RetailerViewHolder> adapter = new FirebaseRecyclerAdapter<RetailerInfo, RetailerViewHolder>(
RetailerInfo.class,
R.layout.distributor_row,
RetailerViewHolder.class,
mDatabase
) {
@Override
protected void populateViewHolder(RetailerViewHolder viewHolder, final RetailerInfo model, final int position) {
viewHolder.setAddress(model.getContactPerson());
viewHolder.setArea(model.getContactNumber());
viewHolder.setShopName(model.getShopName());
viewHolder.setZipcode(model.getZipcode());
viewHolder.setCity(model.getCity());
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// DatabaseReference ref = getRef(position);
// String key= ref.getKey();
// Toast.makeText(Distributors.this, key, Toast.LENGTH_SHORT).show();
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
RetailerInfo retailerInfo = dataSnapshot.getValue(RetailerInfo.class);
Iterator it = retailerInfo.getDistributorInfo().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
Log.d("TAG","distributorInfo: "+pair.getKey() + " = " + pair.getValue());
it.remove(); // avoids a ConcurrentModificationException
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
mDatabase.addListenerForSingleValueEvent(valueEventListener);
}
});
}
};
recyclerView.setAdapter(adapter);
}
-Code für RetailerInfo: -
public class RetailerInfo { String id, Shopname, Adresse, Stadt, Postleitzahl, Gebiet, Kontaktperson, contactNumber, contact_person_email, location_master, Typ, last_vist, last_visited_by, cityname, salesPersonName; HashMap distributorInfo;
public RetailerInfo() {
}
public RetailerInfo(String id, String shopName, String address, String city, String zipcode, String area, String contactPerson, String contactNumber, String contact_person_email, String location_master, String type, String last_vist, String last_visited_by, String cityName, String salesPersonName, HashMap<String, String> distributorInfo) {
this.id = id;
this.shopName = shopName;
this.address = address;
this.city = city;
this.zipcode = zipcode;
this.area = area;
this.contactPerson = contactPerson;
this.contactNumber = contactNumber;
this.contact_person_email = contact_person_email;
this.location_master = location_master;
this.type = type;
this.last_vist = last_vist;
this.last_visited_by = last_visited_by;
this.cityName = cityName;
this.salesPersonName = salesPersonName;
this.distributorInfo = distributorInfo;
}
public HashMap<String, String> getDistributorInfo() {
return distributorInfo;
}
public String getId() {
return id;
}
public String getShopName() {
return shopName;
}
public String getAddress() {
return address;
}
public String getCity() {
return city;
}
public String getZipcode() {
return zipcode;
}
public String getArea() {
return area;
}
public String getContactPerson() {
return contactPerson;
}
public String getContactNumber() {
return contactNumber;
}
public String getContact_person_email() {
return contact_person_email;
}
public String getLocation_master() {
return location_master;
}
public String getType() {
return type;
}
public String getLast_vist() {
return last_vist;
}
public String getLast_visited_by() {
return last_visited_by;
}
public String getCityName() {
return cityName;
}
public String getSalesPersonName() {
return salesPersonName;
}
public void setId(String id) {
this.id = id;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public void setAddress(String address) {
this.address = address;
}
public void setCity(String city) {
this.city = city;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public void setArea(String area) {
this.area = area;
}
public void setContactPerson(String contactPerson) {
this.contactPerson = contactPerson;
}
public void setContactNumber(String contactNumber) {
this.contactNumber = contactNumber;
}
public void setContact_person_email(String contact_person_email) {
this.contact_person_email = contact_person_email;
}
public void setLocation_master(String location_master) {
this.location_master = location_master;
}
public void setType(String type) {
this.type = type;
}
public void setLast_vist(String last_vist) {
this.last_vist = last_vist;
}
public void setLast_visited_by(String last_visited_by) {
this.last_visited_by = last_visited_by;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public void setSalesPersonName(String salesPersonName) {
this.salesPersonName = salesPersonName;
}
}
Jede Hilfe oder Vorschlag wird geschätzt. Danke.
google für GSON Parsing Sie werden die Idee bekommen. –
Danke @SohailZahid wird es jetzt versuchen. – anup
@SohailZahid Firebase stellt das unverarbeitete JSON der Datenbankwerte nicht zur Verfügung, daher ist GSON normalerweise ziemlich nutzlos, wenn Sie nicht zuerst von 'DataSnapshot' von Firebase in JSON konvertieren. –