TextView lEmpty = new TextView(MyListActivity.this); lEmpty.setText("No entry"); getListView().setEmptyView(lEmpty); lEmpty.setVisibility(View.GONE); ((ViewGroup)getListView().getParent()).addView(lEmpty);
At first, I didn't included the last two lines. As a result, the empty view was not showed. First, because the empty view wasn't added to the ViewGroup of the ListView. Also, if the visibility isn't set to GONE, then the view will always be rendered visible. These two operations are handled automatically when using declarative XML views.
Very useful post with explaination
ReplyDelete