I have a real-time firebase database that stores User address. I want to get the values and assign them to textviews
in android layout. I have tried access the data like this:
String city = (mDatabase.getDatabase().getReference().child(user_data.getString("uidkey", null)).child("city")).toString();
_cityText.setText(city);
But that gives me only the firebase URL of the the street and not the actual value. How can I go about retrieving this data?
This is how the database looks like.
public void onStart(){
super.onStart();
final SharedPreferences user_data = getSharedPreferences("PESASEND_PREFS", Context.MODE_PRIVATE);
mDatabase.child(user_data.getString("uidkey", null)).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Address address = dataSnapshot.getValue(Address.class);
// address.getCity();
_state_province_Text.setText(address.getStreet());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
.
public class Address {
public String street;
public String city;
public String state;
public String zip_postal_code;
public String country;
public Address (){};
public Address(String street, String city, String state, String zip_postal_code, String country ){
this.street = street;
this.city = city;
this.state = state;
this.zip_postal_code = zip_postal_code;
this.country = country;
}
public String getStreet (){return street;}
public String getCity (){return city;}
public String getState (){return state;}
public String getZipPostalCode (){return zip_postal_code;}
public String getCountry (){return country;}
}