Call to ListView's setEmpty method not working (nothing is displayed when the list is empty)

Viewed 4127

I have an Activity which contains a ListView defined in XML (its not subclassing the ListActivity class).

I want to display a message when the ListView is empty, so I tried doing so with the setEmptyView method:

listView = (ListView) findViewById(R.id.list);
TextView emptyListText = new TextView(this);
// also tried with the following line uncommented
// emptyListText.setId(android.R.id.empty);
emptyListText.setText(getString(R.string.EmptyList));
listView.setEmptyView(emptyListText);

But it is not working.

Any ideas?

Thanks.

3 Answers
Related