S
S
sanke462017-11-06 13:28:04
Java
sanke46, 2017-11-06 13:28:04

How to display information about a FireBase user?

5a00385a9b356823057921.png
there is such a user base and it is necessary to display the names of all users in the console (but I can only display the name of one user whom I know)

package com.sanke.ilafedoseev.talkchat.UI;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.sanke.ilafedoseev.talkchat.R;

import java.util.HashMap;

public class SearchActivity extends AppCompatActivity {

    private DatabaseReference myRef;
    private FirebaseDatabase mFirebaseDatabase;
    private HashMap<String,String> usersList = new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);

        mFirebaseDatabase = FirebaseDatabase.getInstance();
        myRef = mFirebaseDatabase.getReference();

        myRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                // Как написать правильно код здесь ?
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan0206, 2017-11-07
@Ivan0206

Make Pojo a class with fields corresponding to the fields in the database. Then you get the data from the database and put it into the object of the created Pojo class. Firebase has a special method for this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question