简体   繁体   中英

Android Firebase How to Read the Data from Current User ID?

This is my code I want to read the current user id data from firebase.

DatabaseReference ref2;
ref2=db.getReference("HiringWalker").child(FirebaseAuth.getInstance().getCurrentUser().getUid());

在此处输入图片说明

在此处输入图片说明

I want to read the current user id and -Lwg_.... all the data.

This won't work because you need to go one level deeper, there is one more child that I unknown how you create it

ref2=db.getReference("HiringWalker").child(FirebaseAuth.getInstance().getCurrentUser().getUid());

Do this instead

ref2=db.getReference("HiringWalker").child("ciu12tcL4RfzmC3T6Gdp64LgiZa2").child(FirebaseAuth.getInstance().getCurrentUser().getUid());

Check where are you creating this ciu12tcL4RfzmC3T6Gdp64LgiZa2 and replace that .child("ciu12tcL4RfzmC3T6Gdp64LgiZa2") with the current implementation that generates that random number

Your query is correct, but the fetch data is incorrect, should be modified from

ref2.addValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

    infoList.clear();

    for (DataSnapshot infoSnapshot : dataSnapshot.getChildren())
    {
        for (DataSnapshot infomationsnap : infoSnapshot.getChildren())
        {
            ReWalker rewalker = infomationsnap.getValue(ReWalker.class)
            infoList.add(rewalker);
        }
    }

});

to

ref2.addValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

    infoList.clear();

    for (DataSnapshot infoSnapshot : dataSnapshot.getChildren())
    {
        ReWalker rewalker = infoSnapshot.getValue(ReWalker.class)
        infoList.add(rewalker);
    }

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM