作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想查询多个节点中的特定子值,以通过 FirebaseListAdapter 在 ListView 中填充它们。我将一个 firebase 引用传递给 FirebaseListAdapter 方法来监听,它在下图中的红色矩形中,并且 我只想在 ListView 中填充“类别”键的值。下图中的绿色矩形。
我的代码在这里:
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);
}
};
关于android - 如何使用firebase android查询多个节点中的特定子值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37558909/
我是一名优秀的程序员,十分优秀!