本文整理汇总了Java中com.firebase.client.Query.addListenerForSingleValueEvent方法的典型用法代码示例。如果您正苦于以下问题:Java Query.addListenerForSingleValueEvent方法的具体用法?Java Query.addListenerForSingleValueEvent怎么用?Java Query.addListenerForSingleValueEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.firebase.client.Query
的用法示例。
在下文中一共展示了Query.addListenerForSingleValueEvent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderData
import com.firebase.client.Query; //导入方法依赖的package包/类
private void renderData() {
Query queryRef = mRootRef.child("users").orderByChild(getOrderBy()).limitToLast(100);//we need to iterate them backwards
queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot userSnapshot : snapshot.getChildren()) {
mUsersDataset.add(userSnapshot.getValue(User.class));
}
Collections.reverse(mUsersDataset);
mAdapter = new UserListAdapter(mUsersDataset, getActivity(), getmTabType());
mRecyclerView.setAdapter(mAdapter);
mLoadingWrapper.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
示例2: getPosts
import com.firebase.client.Query; //导入方法依赖的package包/类
@Override
public Post[] getPosts(int numPosts) {
Query query = firebasePostsRef.orderByChild("timestamp").limitToLast
(numPosts);
countDownLatch = new CountDownLatch(1);
ValueEventListener callbackListener =
newValueEventListenerForSynchronizingCallback();
query.addListenerForSingleValueEvent(callbackListener);
waitForCallback();
if (dataFromCallback != null) {
return parsePostsFromDataSnapshot(dataFromCallback.get());
} else {
return new Post[0];
}
}
示例3: getPostsByUser
import com.firebase.client.Query; //导入方法依赖的package包/类
@Override
public Post[] getPostsByUser(String userId) {
Query query = firebasePostsRef.orderByChild("authorId").equalTo(userId);
countDownLatch = new CountDownLatch(1);
ValueEventListener callbackListener =
newValueEventListenerForSynchronizingCallback();
query.addListenerForSingleValueEvent(callbackListener);
waitForCallback();
if (dataFromCallback != null) {
return parsePostsFromDataSnapshot(dataFromCallback.get());
} else {
return new Post[0];
}
}
示例4: getImagesByUser
import com.firebase.client.Query; //导入方法依赖的package包/类
@Override
public FirebaseImage[] getImagesByUser(String ownerUid) {
Query userImagesQuery = imagesRef
.orderByChild("ownerUid")
.equalTo(ownerUid);
final AtomicReference<DataSnapshot> snapshotAtomicRef = new
AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
userImagesQuery.addListenerForSingleValueEvent(new ValueEventListener
() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
snapshotAtomicRef.set(dataSnapshot);
latch.countDown();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
throw firebaseError.toException();
}
});
awaitLatch(latch);
return parsePostsFromDataSnapshot(snapshotAtomicRef.get());
}
示例5: executeCommentQuerySynchronously
import com.firebase.client.Query; //导入方法依赖的package包/类
@NonNull
private Comment[] executeCommentQuerySynchronously(Query query) {
countDownLatch = new CountDownLatch(1);
query.addListenerForSingleValueEvent
(getValueEventListenerForSynchronizingCallbacks());
waitForCallback();
return parseCommentsFromCallbackData();
}
示例6: set
import com.firebase.client.Query; //导入方法依赖的package包/类
@Override
protected void set(Query query) {
query.addListenerForSingleValueEvent(this);
}