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

1

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.

Abuttal answered 13/12, 2012 at 14:32 Comment(0)
V
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

Versus answered 13/12, 2012 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.