我正在尝试从Android应用中的Firebase中获取特定数据。 在onCreate中我定义了我的DatabaseReference和ArrayList:
databaseRef = FirebaseDatabase.getInstance().getReference("books");
books = new ArrayList<>();
然后用数据填充我的ListView:
@Override
protected void onStart() {
super.onStart();
databaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
books.clear();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String uid = user.getUid();
//iterating through all the nodes
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Book bookrequest = postSnapshot.getValue(Book.class);
books.add(bookrequest );
}
}
BooksListing booksAdapter = new BooksListing(MainActivity.this, books);
//attaching adapter to the listview
listViewBooks.setAdapter(booksAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
现在我只想从Firebase获取具有我自己的UID的书籍。
type books {
id: String;
amount: Number;
uid: uid;}
在将数据传输到Android设备之前,我可以在哪里实现查询?
答案 0 :(得分:2)
试试这个:
{{1}}
希望这有帮助