数据结构
Users_Node
{
UserID1
{
firstName:...
lastName:...
...
}
UserID2
{
firstName:...
lastName:...
...
}
UserID3
{
firstName:...
lastName:...
...
}
UserID4
{
firstName:...
lastName:...
...
}
UserID5
{
firstName:...
lastName:...
...
}
.
.
.
.
.
.
UserID10000
{
firstName:...
lastName:...
...
}
}
User_Chat_Node
{
.....
}
Other_Nodes....
{
}
如何获取一些预先知道的ID的详细信息,请说UserID4,UserID5,UserID2000,UserID2005。
选项1)
mRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
CurrentUserDetails = dataSnapshot.getValue(UserDetails.class);
//Add the item to my Array
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
问题 - 列表工具将被创建10000次。
选项2)
Parent_mRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
//if(RequiredID == dataSnapshot.getValue(UserDetails.class).getUserID() )
//Add the item to my Array
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
问题 - 必须循环10000次。
是不是像
那样简单//For each item in MyListofUserIDs
{
MyArray [location] = Parent_ref.child(MyListofUserIDs[location]).getValue(UserDetails.class)
}