0
我試圖獲取獨特的兒童名稱,但其始終返回相同的ID,或者它返回了我爲兒童引用的內容。如何在Firebase中獲取兒童名稱Android
UID保持「用戶」而不是行駛到用戶
我試着讓孩子名下的用戶這是長鍵/字符串:
public class displayUserBooks extends AppCompatActivity {
ListView listViewBooks;
List<existingBooks> existingBookses;
private FirebaseAuth mAuth;
FirebaseDatabase databaseViewbooks = FirebaseDatabase.getInstance();
DatabaseReference myRef = databaseViewbooks.getReference("Books");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_user_books);
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
listViewBooks= (ListView) findViewById(R.id.listViewBooks);
existingBookses = new ArrayList<>();
}
@Override
protected void onStart() {
super.onStart();
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
checkBooks(dataSnapshot);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void checkBooks(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
String uid=ds.child("users").getKey();
existingBooks eBooks = new existingBooks();
eBooks = ds.getValue(existingBooks.class);
// if(user.getUid().equals(uid))
existingBookses.add(eBooks);
}
Booklist adapter = new Booklist(displayUserBooks.this,existingBookses);
listViewBooks.setAdapter(adapter);
}}
重複? https://stackoverflow.com/q/40101010/1531971 – jdv
@jdv當我鍵入.getKey()我只拿到外鍵(第一個孩子),而不是用戶鍵(用戶是第一個孩子的孩子) –
你顯然需要不同的方法 – Chisko