0
什么是正确的方式来查询附加到Android中的照片(POJO)的每个评论(POJO)。在火力地堡,我有一个照片集的结构如下:Firebase - 从Android中的FirebaseListAdapter查询
"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
}
}
和意见收集:
"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
}
}
在Android中我使用的是FirebaseAdapter,但我有一个定义适当的查询麻烦那只会检索附加到特定照片的评论。我的照片
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());
}
};
的关键,我想我可以定义是这样的:
final FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference commentsRef = database.getReference("comments");
Query query = commentsRef.orderByChild("attachphoto").equalTo()
但我有一个关于如何完成这个有些脱节。首先使用Firebase的项目,所以任何帮助/技巧将非常感谢!
看起来好像你正试图将评论分类。见http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value –
谢谢你的工作! StringBuilder child = new StringBuilder(“attachphoto /”); child.append(imageKey); Query query = commentsRef.orderByChild(child.toString())。equalTo(Boolean.TRUE); – gareoke