Android displaying text when ListView is empty

I’m guessing you are using a regular Fragment or Activity with a ListView inside of it. If you are, you must add the empty layout to the ListView manually.

E.g.

ListView lv = (ListView)findViewById(android.R.id.list);
TextView emptyText = (TextView)findViewById(android.R.id.empty);
lv.setEmptyView(emptyText);

Then your ListView will automatically use this view when its adapter is empty

If you are using a ListActivity you do not need to call setEmptyView() on the ListView since the ListActivity automatically manages that for you.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)