How to display Firebase data on Android

0

Good, I have some data in my BDB of FireBase (Name, Surname, DNI) that are created based on a Mail.

I've been looking for how to show that data on an Android screen but I can not find anything, someone has some idea of how I could show them ??

And another thing, as I said every account is created with an email, is there no way to put the Mail instead of a Random Key? I have not seen it anywhere.

    
asked by Cristian Prieto Beltran 04.04.2017 в 12:33
source

3 answers

3

You can create an item in Firebase with the identifier you need in the following way:

FirebaseDatabase.getInstance().getReference("Usuarios")
                           .child(email).setValue(userInfo);

But keep in mind that the "key" of any firebase record can not carry any of the following characters, so you can not use the mail as such for the point.

  • . (period)
  • $ (dollar sign)
  • [(left square bracket)
  • ] (right square bracket)
  • '#' (hash or pound sign)
  • / (forward slash)

To display the information I recommend the RecyclerView, you can read here about the component

    
answered by 12.04.2017 в 23:34
0

In firebase when creating a new node the key that generates itself is a UID which to obtain it is with getkey .

final String UID=databaseReference.getKey();

But if you want to return all the nodes use a recyclerview for which you will create a ViewHolder and you will need to create a layout in the will be the container of each node that will be created from the database.

    
answered by 04.04.2017 в 19:59
0

Initially you must create an instance to your "users" table

  • Implement a recyclerView with its respective adapter
  • Implement the listener
  • Print values

    private DatabaseReference userDatabase
    //en el onCreate creas la instancia
    userDatabase = FirebaseDatabase.getInstance().getReference(FirebaseReference.USUARIOS_REFERENCE);
    //Creas tu adapter y recycler y agregamos el listener
    ValueEventListener userListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                Usuarios users = snapshot.getValue(Usuarios.class);
                list_usuarios.add(users);
                Log.d("users",users.getUser() + "usename -> " +  
            users.getEmail());
    
            }
            tuAdapter.notifyDataSetChanged();
      }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {
    
        }
    };
    userDatabase.addValueEventListener(userListener);
    
  • answered by 15.02.2018 в 17:15