I'm using a FirebaseListAdapter and overriding the required onPopulateView method to gather data from a Realtime Database, and then setting the adapter to a ListView in the UI:
mMessageSummaryAdapter = new FirebaseListAdapter<MessageSummary> (getActivity(),
MessageSummary.class, R.layout.message_list_item, mChatDbReference) {
@Override
protected void populateView(View v, MessageSummary msgSummary, int position) {
final ImageView buddyImage = (ImageView) v.findViewById(R.id.small_image_view_messages);
final TextView buddyName = (TextView) v.findViewById(R.id.contact_username);
....
mListView.setAdapter(mMessageSummaryAdapter);
With other adapters that I've used, it is possible to check whether the data going into it is null or not, and set the visibility of the view accordingly, and pull in an empty view if data is null:
if (foundRoutesList == null || foundRoutesList.size() == 0) {
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
} else {
mEmptyView.setVisibility(View.GONE);
mAdapter = new SearchResultsAdapter(getContext(), foundRoutesList, this);
mRecyclerView.setAdapter(mAdapter);
}
As I understand it, the FirebaseListAdapter iterates through found items and adds them one by one, so how can I test to see if the result is empty so an empty text view can be displayed instead?
To solve this, override FirebaseListAdapter's getCount() method in your adapter class and check for nullity:
if(getCount() == 0) {
mEmptyView.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
} else {
mEmptyView.setVisibility(View.GONE);
mAdapter = new SearchResultsAdapter(getContext(), foundRoutesList, this);
mRecyclerView.setAdapter(mAdapter);
}