ListView has a special method - setEmptyView() . You can find usage examples here or here .
Update: The second link is not available. Here is a quote from the article:
When you arbitrarily set the "empty view" of ListViews, you can scratch your head about why your empty view does not actually appear when the list is empty.
If this happens, then you forgot that you must manually add your empty view to your view hierarchy, because the ListView will not do this for you. Although this is obvious when you think about it, the documentation does not mention this detail, and Googling shows that one person had the problem.
Here is the code with lines that are too easy to forget on numbers 4 and 5 ...
TextView emptyView = new TextView(context); emptyView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); emptyView.setText("This appears when the list is empty"); emptyView.setVisibility(View.GONE); ((ViewGroup)list.getParent()).addView(emptyView); list.setEmptyView(emptyView);
source share