Wie ist die richtige Abfrage für jedes Kommentar (POJO) an ein Foto (POJO) in Android. In Firebase habe ich die folgende Struktur für eine Fotosammlung:Firebase - Abfragen von FirebaseListAdapter in Android
"photos" : {
"-KaeuYf9jXcy4oqpRqbi" : {f
"entities" : {
"type" : {
"image" : {
"bucket" : "bucket",
"prefix" : "https://s3-us-west-2.amazonaws.com/",
"suffix" : "image.jpg"
}
}
},
"stats" : {
"liked" : 0
},
"text" : "Person Detected!",
"timestamp" : 1484631194257
}
}
und für Kommentare Sammlung:
"comments" : {
"-KdE6Hwua8d6sBQimPos" : {
"attachphoto" : {
"-KaeuYf9jXcy4oqpRqbi" : true
},
"attachuser" : {
"-KaeuYHjkdf9okflslf" : true
},
"displayName" : "Gary",
"text" : "ok",
"timestamp" : 1487385995844
},
"-KdE6IPc-NL-6zGkwXq3" : {
"attachphoto" : {
"-KaeuYf9jXcy4oqpRqbi" : true
},
"attachuser" : {
"-KaeuYHjkdf9okflslf" : true
},
"displayName" : "Thomas",
"text" : "ok",
"timestamp" : 1487385997735
}
}
in Android Ich bin mit einem FirebaseAdapter, aber ich habe Probleme, die eine korrekte Abfrage Das würde nur Kommentare abrufen, die an ein bestimmtes Foto angehängt sind. Ich habe den Schlüssel des Photo
FirebaseListAdapter adapter = new CommentAdapter(this, Comment.class, R.layout.item_comment, QUERY){
@Override
protected void populateView(View v, Comment model, int position) {
if(model.getDisplayName()!=null) {
String[] name = model.getDisplayName().split(" ");
((TextView) v.findViewById(R.id.id)).setText(name[0]);
}
((TextView) v.findViewById(R.id.content)).setText(model.getText());
}
};
Ich dachte, ich so etwas wie definieren könnte:
final FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference commentsRef = database.getReference("comments");
Query query = commentsRef.orderByChild("attachphoto").equalTo()
Aber ich habe einige trennen, wie dies zu beenden. Erstes Projekt mit Firebase, also jede Hilfe/Tipps würden sehr geschätzt werden!
Es scheint, als ob Sie versuchen, die Kommentare in Kategorien einzuteilen. Siehe http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value –
Danke das hat funktioniert! StringBuilder child = new StringBuilder ("attachphoto /"); child.append (Bildschlüssel); Abfrage abfragen = commentsRef.orderByChild (child.toString()). EqualTo (Boolean.TRUE); – gareoke