Google Firebase Android app receiving wrong db information from DataSnapshot -
i making android app require google firebase, , in app have iterate through datasnapshots couple of times. in 1 specific instance, datasnapshop passing data different directory in database specified to. make reference database, add event listener calls ondatachange method passes datasnapshot through. here:
nref = mfirebasedatabase.getreference(); nref.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { if (datasnapshot.exists()){ showdatalobreq(datasnapshot); showdata(datasnapshot); } else { } } @override public void oncancelled(databaseerror databaseerror) { } });
and here methods calls:
public void showdatalobreq(datasnapshot datasnapshot){ for(datasnapshot ds : datasnapshot.child("lobby_requests").getchildren()){ system.out.println("here"+ds.getvalue()); game = ds.child(userid).child("game").getvalue(string.class); console = ds.child(userid).child("console").getvalue(string.class); mic = ds.child(userid).child("mic").getvalue(string.class); players = ds.child(userid).child("players").getvalue(string.class); } } public void showdata(datasnapshot datasnapshot){ arraylist<lobbyinformation> lobbies = new arraylist<>(); iterator<datasnapshot> items = datasnapshot.child("lobbies").getchildren().iterator(); lobbies.clear(); while(items.hasnext()){ lobbyinformation lobby = new lobbyinformation(); datasnapshot item = items.next(); lobby.setgamename(item.child("game").getvalue(string.class)); lobby.setconsole(item.child("console").getvalue(string.class)); lobby.setmic(item.child("mic").getvalue(string.class)); lobby.setnote(item.child("note").getvalue(string.class)); lobby.setplayercounttotal(item.child("players").getvalue(string.class)); lobby.sethost(userid); if(console.equals(item.child("console").getvalue(string.class)) && players.equals(item.child("players").getvalue(string.class)) && mic.equals(item.child("mic").getvalue(string.class)) && game.equals(item.child("game").getvalue(string.class))){ lobbies.add(lobby); } } arrayadapter adapter = new customlistadapterlobby(this, lobbies); lobbylistview.setadapter(adapter); }
in first method calls "showdatalobreq" can see use system.out.println see contents of datasnapshot, , discovered showing contents child of datasnapshot iterate through in second method "showdata". have no idea why considering define correct child in enhanced loop @ beginning of method "showdatalobreq".
Comments
Post a Comment