0

my database :

class UserAccountSettings {
    private String user_id;
    private String name ;
    private float rate;
    private String profile_photo;
    private ArrayList<Activity> activities ;
} 

thanks for your help!

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Chouaieb
  • 11
  • 1
  • 5

2 Answers2

1

To display those values, please use the following code:

String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference activitiesRef = rootRef.child("user_account_settings").child(uid).child("activities");
ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        String user_id = dataSnapshot.child("user_id").getValue(String.class);
        String name = dataSnapshot.child("name").getValue(String.class);
        float rate = dataSnapshot.child("rate").getValue(Float.class);
        String profile_photo = dataSnapshot.child("profile_photo").getValue(String.class);
        Log.d("TAG", user_id + " / " +
            profile_photo + " / " +
            rate + " / " +
            profile_photo);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {}
};
activitiesRef.addListenerForSingleValueEvent(valueEventListener);

The output will be:

mVeg... / Debbebi / 0 / http://...
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • **[This](https://stackoverflow.com/questions/49383687/how-can-i-retrieve-data-from-firebase-to-my-adapter/49384849)** is how you can retrieve data from a Firebase Realtime database and display it in a `RecyclerView` using `FirebaseRecyclerAdapter`. – Alex Mamo May 09 '18 at 17:22
  • @Alex Mamo Your code is perfect but 1 question is there. How to get "location" data in your code? – ravi152 Nov 26 '18 at 12:57
  • @ravi152 Thanks! I don't understand about what location you are you talking but I recommend you post another fresh question, so me and other users can help you. – Alex Mamo Nov 26 '18 at 13:01
  • @Alex Mamo location filed which is in question firebase table. i talk about that location which is in every table below description text. – ravi152 Nov 27 '18 at 05:30
0
  1. declare a Data baseReference object (edit the string "azone" to match with your node key):

    DatabaseReference userSettingRef = 
                    FirebaseDatabase.getInstance().getReference()
                            .child("azone")
                            .child("user_account_settings")
                            .child(getUserId());
    
  2. add a ValueEventListener:

    userSettingRef.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        // Get Post object and use the values to update the UI
                        UserAccountSettings setting = dataSnapshot.getValue(UserAccountSettings .class);
                    if (setting!= null) {
                       // do something here
    
                    }
    
                }
    
                @Override
                public void onCancelled(DatabaseError databaseError) {
                    // Getting Post failed, log a recipientMessage
                    Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
                    // ...
                }
            });
    
Fazan Cheng
  • 866
  • 1
  • 8
  • 13