I cannot return data from the firebase user to display in edittext, how do I?

Asked

Viewed 39 times

0

The Code I’m using is this:

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

        mTextView = (TextView) findViewById(R.id.textFarm);

        FirebaseDatabase mDatabase = FirebaseDatabase.getInstance();
        mDataBaseRef = ConfiguracaoFirebase.getFirebase().child("usuario").child("nome");

        mDataBaseRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                String s = dataSnapshot.getValue(String.class);

                Toast.makeText(CotacaoActivity.this, "O que aparece! " + s, Toast.LENGTH_SHORT).show();

                setTextView(s);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                setTextView(databaseError.toString());
            }
        });

O Firebase está assim.

I need to insert this name into a Textview. It only returns null. I’ve tried several examples and answers from you. Someone can help.

  • 2

    .child("usuario").child("nome") does not exist. It has to be .child("usuario").child("{ID_DO_USUARIO}").child("nome"). At least according to the structure you posted there in the image

  • Ok. Then I put the user id and it will display the name? mDataBaseRef = Configuracaofirebase.getFirebase(). Child("user"). Child(userid). Child("name");

  • Probably

  • I checked that the mDataBaseRef user is null, even after logging in to Activity login (first Activity). After logging in the main screen opens with the menus, and it chooses which one should go, when entering new Activity (third ativity) the user is presented as null.

  • I did the check like this: "Toast.makeText(Cotacaoactivity.this, "What appears! " + mDataBaseRef, Toast.LENGTH_SHORT). show();" The return of "mDataBaseRef=null". Can anyone indicate why the user name is null? Called here: mDataBaseRef = Configuracaofirebase.getFirebase(). Child("user"). Child(userid). Child("name");and thereby not displaying the user’s name?

  • I got it sorted out! It was careless of me.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.