I want to query a specific child value in multiple nodes, to populate them in a list view by FirebaseListAdapter. I'm passing a firebase reference to FirebaseListAdapter method to listen to, which is in red rectangle in the picture below, And I want to populate in the list view the values of the "category" key only. which are in green rectangle in the picture below.
My code is here:
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);
And the layout for the listView containing a TextView to display the category name.
You'll need to override
FirebaseListAdapter.parseDataSnapshot()
to extract the right value from theDataSnapshot
: