java - Storing firebase values into an array? Keep getting zero -
i trying store userid's uidmatches. when first println getting correct string array of matches, when second 1 says uidmatches array has nothing in it... "[ ]". don't see how possible.
private void populatelistview() { final arraylist<string> uidmatches = new arraylist<string>(); final arraylist<profile> match_profiles = new arraylist<profile>(); users = database.getreference("users"); user = firebaseauth.getinstance().getcurrentuser(); matches = database.getreference("matches").child(user.getuid()); // returns uid's profiles matched matches.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { (datasnapshot child : datasnapshot.getchildren()) { string match = child.getvalue().tostring(); uidmatches.add(match.tostring()); system.out.println("here matches 1: " + uidmatches); } } @override public void oncancelled(databaseerror databaseerror) { } }); system.out.println("here matches 2: " + uidmatches); // loop profiles match each "uidmatches" uid (int x=0; x<uidmatches.size(); x++) { users.child(uidmatches.get(x)).addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { (datasnapshot child : datasnapshot.getchildren()) { profile profile = child.getvalue(profile.class); match_profiles.add(profile); } } @override public void oncancelled(databaseerror databaseerror) { } }); } }
picture of firebase setup. blocked out users unique id's generated fb login
this isn't firebase issue it's java problem. println @ end of code gets run when code first starts when array empty. other println gets fired ondatachange after results populated.
Comments
Post a Comment