![](/img/trans.png)
[英]in android with firebase as baas service,how to retrive only specific child nodes
[英]How to query a specific child value in multiple nodes with firebase android
我想查询多个节点中的特定子值,以便通过FirebaseListAdapter在列表视图中填充它们。 我正在通过firebaseListAdapter方法的firebase引用来监听,这是在下面的图片中的红色矩形, 并且我想在列表视图中填充“类别”键的值。 在下图中为绿色矩形。
我的代码在这里:
catgoryList = (ListView) findViewById(R.id.catList);
rootRef = FirebaseDatabase.getInstance().getReference();
restaurantMenuRef = rootRef.child("menu").child(restaurantID);
FirebaseListAdapter<String> listAdapter = new FirebaseListAdapter<String>
(this, String.class, R.layout.menu_list_item, restaurantMenuRef ) {
@Override
protected void populateView(View v, String s, int position) {
TextView menuName = (TextView)v.findViewById(R.id.menuName);
menuName.setText(s);
}
};
catgoryList.setAdapter(listAdapter);
并且包含TextView的listView的布局显示类别名称。
您需要覆盖FirebaseListAdapter.parseDataSnapshot()
以从DataSnapshot
提取正确的值:
FirebaseListAdapter<String> listAdapter = new FirebaseListAdapter<String>
(this, String.class, R.layout.menu_list_item, restaurantMenuRef ) {
@Override
protected String parseSnapshot(DataSnapshot snapshot) {
return snapshot.child("category").getValue(String.class);
}
@Override
protected void populateView(View v, String s, int position) {
TextView menuName = (TextView)v.findViewById(R.id.menuName);
menuName.setText(s);
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.