Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How do I emulate the behavior of @android:id/empty in a GridView?

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.

like image 660
ambit Avatar asked Dec 13 '12 14:12

ambit


1 Answers

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

like image 178
dymmeh Avatar answered Oct 04 '22 21:10

dymmeh