本文整理了Java中com.google.firebase.database.Query.addValueEventListener
方法的一些代码示例,展示了Query.addValueEventListener
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.addValueEventListener
方法的具体详情如下:
包路径:com.google.firebase.database.Query
类名称:Query
方法名:addValueEventListener
[英]Add a listener for changes in the data at this location. Each time time the data changes, your listener will be called with an immutable snapshot of the data.
[中]在此位置添加数据更改的侦听器。每次数据更改时,您的侦听器都会被调用一个不可变的数据快照。
代码示例来源:origin: FrangSierra/RxFirebase
@Override
public void subscribe(final FlowableEmitter<DataSnapshot> emitter) throws Exception {
final ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
emitter.onNext(dataSnapshot);
}
@Override
public void onCancelled(final DatabaseError error) {
if (!emitter.isCancelled())
emitter.onError(new RxFirebaseDataException(error));
}
};
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
query.removeEventListener(valueEventListener);
}
});
query.addValueEventListener(valueEventListener);
}
}, strategy);
代码示例来源:origin: yongjhih/rxfirebase
private void verifyQueryAddValueEventListener() {
verify(mockQuery)
.addValueEventListener(valueEventListener.capture());
}
代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app
@Override
public void fetchResources(int startFrom, int limit, Callback<List<Resource>> callback) {
ValueEventListener listener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot != null) {
List<Resource> resources = new ArrayList<>();
for (DataSnapshot childSnapshot : snapshot.getChildren()) {
Resource resource = childSnapshot.getValue(Resource.class);
resources.add(resource);
}
callback.onReponse(resources);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
callback.onError();
}
};
Query resourcesQuery = mResourcesRef.orderByChild(KEY_TIMESTAMP);
if (limit > 0) {
resourcesQuery.limitToFirst(limit);
}
resourcesQuery.addValueEventListener(listener);
mValueListeners.add(listener);
}
代码示例来源:origin: TomGrill/gdx-firebase
@Override
public ValueEventListener addValueEventListener(final ValueEventListener listener) {
com.google.firebase.database.ValueEventListener fbListener = new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
listener.onDataChange(new DesktopDataSnapshot(dataSnapshot));
}
@Override
public void onCancelled(DatabaseError databaseError) {
listener.onCancelled(new DesktopDatabaseError(databaseError));
}
};
query.addValueEventListener(fbListener);
fbValueEventListenerList.add(fbListener);
valueEventListenerList.add(listener);
return listener;
}
代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app
quizzesRefQuery.limitToFirst(limitToFirst);
quizzesRefQuery.addValueEventListener(listener);
mValueListeners.add(listener);
代码示例来源:origin: UdacityAndroidBasicsScholarship/audacity
private void setHottestAppData() {
mDbRef.child(Constants.HOTTEST_APP_STRING).limitToLast(1).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
HottestApp hottestApp = snapshot.getValue(HottestApp.class);
mHottestAppTitle.setText(hottestApp.getAppTitle());
mHottestStudentName.setText(hottestApp.getStudentName());
mHottestPostedOn.setText(Helpers.formatDate(hottestApp.getPostedDate()));
String profileImage = hottestApp.getProfileImage();
if (profileImage != null) {
Glide.with(mContext).load(profileImage).into(mHottestProfileImage);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
代码示例来源:origin: UdacityAndroidBasicsScholarship/audacity
private void setChallengeData() {
mDbRef.child(Constants.CHALLENGES_STRING).limitToLast(1).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Challenge challenge = snapshot.getValue(Challenge.class);
mChallengeName.setText(challenge.getChallengeName());
mChallengeModName.setText(challenge.getModeratorName());
mChallengeEndDate.setText(Helpers.formatDate(challenge.getStartDate()));
String profileImage = challenge.getProfileImage();
if (profileImage != null) {
Glide.with(mContext).load(profileImage).into(mChallengeProfileImage);
}
}
mRootView.setVisibility(View.VISIBLE);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
代码示例来源:origin: yongjhih/rxfirebase
@Override
public void subscribe(
@NonNull final ObservableEmitter<DataSnapshot> emit) throws Exception {
final ValueEventListener listener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (!emit.isDisposed()) {
emit.onNext(dataSnapshot);
}
}
@Override
public void onCancelled(DatabaseError e) {
if (!emit.isDisposed()) {
emit.onError(e.toException());
}
}
};
emit.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
query.removeEventListener(listener);
}
});
query.addValueEventListener(listener);
}
});
代码示例来源:origin: UdacityAndroidBasicsScholarship/scholar-quiz
private void fetchChannelName(final String channelId){
AppInfo.databaseReference.child("ChannelList").child(channelId).orderByKey()
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot channelSnapshot) {
LessonListModel lessonListModel = channelSnapshot.getValue(LessonListModel.class);
String channelName = lessonListModel.getChannelName();
getSupportActionBar().setTitle(channelName);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
代码示例来源:origin: firebase/snippets-android
public void basicQueryValueListener() {
String myUserId = getUid();
Query myTopPostsQuery = databaseReference.child("user-posts").child(myUserId)
.orderByChild("starCount");
// [START basic_query_value_listener]
// My top posts by number of stars
myTopPostsQuery.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
// TODO: handle the post
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
});
// [END basic_query_value_listener]
}
代码示例来源:origin: FrangSierra/RxFirebase
@Test
public void testObserveListWithDataSnapshotCustomMapper() throws Exception {
//noinspection unchecked
Function<DataSnapshot, ChildData> mapper = (Function<DataSnapshot, ChildData>) mock(Function.class);
doReturn(childData).when(mapper).apply(eq(dataSnapshot));
TestSubscriber<List<ChildData>> testObserver = RxFirebaseDatabase
.observeValueEvent(query, DataSnapshotMapper.listOf(ChildData.class, mapper))
.test();
ArgumentCaptor<ValueEventListener> argument = ArgumentCaptor.forClass(ValueEventListener.class);
verify(query).addValueEventListener(argument.capture());
argument.getValue().onDataChange(dataSnapshot);
verify(mapper).apply(dataSnapshot);
testObserver.assertNoErrors()
.assertValueCount(1)
.assertValueSet(Collections.singletonList(childDataList))
.assertNotComplete()
.dispose();
}
代码示例来源:origin: FrangSierra/RxFirebase
@Test
public void testObserveListWithDataSnapshotMapper() {
TestSubscriber<List<ChildData>> testObserver = RxFirebaseDatabase
.observeValueEvent(query, DataSnapshotMapper.listOf(ChildData.class))
.test();
ArgumentCaptor<ValueEventListener> argument = ArgumentCaptor.forClass(ValueEventListener.class);
verify(query).addValueEventListener(argument.capture());
argument.getValue().onDataChange(dataSnapshot);
testObserver.assertNoErrors()
.assertValueCount(1)
.assertValueSet(Collections.singletonList(childDataList))
.assertNotComplete()
.dispose();
}
代码示例来源:origin: UdacityAndroidBasicsScholarship/scholar-quiz
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot channelSnapshot) {
代码示例来源:origin: UdacityAndroidBasicsScholarship/scholar-quiz
private void attachToBeSubscribedChannelListner() {
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot channelSnapshot) {
代码示例来源:origin: riggaroo/android-things-electricity-monitor
logsRef.limitToLast(1).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
内容来源于网络,如有侵权,请联系作者删除!