I am trying to avoid the asynchronous layout pefromaed naturally with Firebase. so I am trying to complete my method in the one dataonchanged method.
I need to know is it possible and how i can reference 2 nodes as you can see , using the one reference. iv tried something like
dataBaseLastIn = FirebaseDatabase.getInstance().getReference("clockInDate" + "clockOutDate");
//and
dataBaseLastIn = FirebaseDatabase.getInstance().getReference("clockInDate");
dataBaseLastIn = FirebaseDatabase.getInstance().getReference("clockOutDate");
//Method that works to set text to one reference but not both
protected void onStart() {
super.onStart();
final String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
dataBaseLastIn.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dateinList.clear();
dateOutList.clear();
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Date date = postSnapshot.getValue(Date.class);
String datt = date.getDate().toString().trim();
String user = date.getCurrUser().toString().trim();
if (DateNew.equals(datt) && user.equals(uid)) {
dateinList.add(date);
} else {
dateinList.remove(date);
}
DateOut dateOut = postSnapshot.getValue(DateOut.class);
String dattOut = dateOut.getDate().toString().trim();
String userOut = dateOut.getCurrUser().toString().trim();
if (DateNew.equals(dattOut) && userOut.equals(uid)) {
dateOutList.add(dateOut);
} else {
dateOutList.remove(date);
}
}
newList = dateinList;
outList = dateOutList;
try {
totalINList();
} catch (ParseException e) {
e.printStackTrace();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
//setting the text
public void totalINList() throws ParseException {
for(int i = 0 ; i < newList.size(); i++) {
timeDuration.add(newList.get(i).getClockTime());
}
Date e = newList.get(newList.size() - 1);
String timeIn = e.getClockTime();
txtCurrentTime.setText(timeIn);
for(int i = 0 ; i < outList.size(); i++) {
timeDurationOut.add(outList.get(i).getTime());
}
DateOut f = outList.get(outList.size() - 1);
String timeOut = f.getTime();
txtCurrentTimeOut.setText(timeOut);
}
May be something simple but i only get the value of the last reference i declare which obviously makes sense but was wondering is ther a way i can reference both nodes in the one