9

I have a gridview that is populated by a cursor that fetches data from SQLITE database. At times, there is no data to be shown. This shows a blank activity.

I had earlier used listview where I could use @android:id/empty to set an emptyView like "no data found".

Is there any similar feature for GridView that I can make use of?

Kindly help.

ambit
  • 1,099
  • 2
  • 28
  • 43

1 Answers1

10

ListActivity and ListFragment simply search for a view with that ID and call

listView.setEmptyView(emptyView);

You can mimic this behavior in your GridView..

TextView emptyView = (TextView)findViewById(android.R.id.empty);
gridView.setEmptyView(emptyView);

Note that you don't need to set your empty view's ID to @android:id/empty. It can be anything you want as long as you are setting it in code.

Link to GridView setEmptyView docs

dymmeh
  • 22,247
  • 5
  • 53
  • 60