0
子があるかどうかをチェックしたい。私はデータがあると、呼び出されていない子がないときにOnChildAdded
の中に入りますか?データがあるかどうかを知りたいのですか?これをどうやってチェックするのですか?その名のとおりデータがないときFirebase onChildAddedが呼び出されない
ref.orderByKey().startAt(todayDate).endAt(tomorrowDate).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
System.out.println("does the child exist? " + dataSnapshot.child("matches").exists());
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
AvailableRidesFirebaseObject rides = postSnapshot.getValue(AvailableRidesFirebaseObject.class);
AvailableRidesFirebaseObject availableRidesFirebaseObject = new AvailableRidesFirebaseObject();
availableRidesFirebaseObject.setAdded_on(rides.getAdded_on());
availableRidesFirebaseObject.setCode(rides.getCode());
availableRidesFirebaseObject.setTime(rides.getTime());
availableRidesFirebaseObject.setDate_of_ride(rides.getDate_of_ride());
availableRidesFirebaseObject.setDay(rides.getDay());
availableRidesFirebaseObject.setDropoff_location(rides.getDropoff_location());
availableRidesFirebaseObject.setDropoff_coordinate(rides.getDropoff_coordinate());
availableRidesFirebaseObject.setFullname(rides.getFullname());
availableRidesFirebaseObject.setOffered_by(rides.getOffered_by());
availableRidesFirebaseObject.setPickup_location(rides.getPickup_location());
availableRidesFirebaseObject.setPickup_coordinate(rides.getPickup_coordinate());
availableRidesFirebaseObject.setSeats(rides.getSeats());
availableRidesFirebaseObject.setShare(rides.getShare());
availableRidesFirebaseObject.setVechile_type(rides.getVechile_type());
availableRidesList.add(availableRidesFirebaseObject);
filteredList.add(rides);
Logger.e("list" ,filteredList.toString());
}
try{
adapter = new RecyclerViewAdapter(getActivity(), availableRidesList);
availableRideListView.setHasFixedSize(true);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext());
availableRideListView.setLayoutManager(mLayoutManager);
availableRideListView.setAdapter(adapter);
loading.setVisibility(View.GONE);
}catch(NullPointerException ne){
ne.printStackTrace();
/*if(availableRidesList.size()==0){
loading.setVisibility(View.GONE);
}*/
}
}
@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) {
}
});