I’ve got a Fragment whose onCreateView() callback returns a custom View. The View contains a GridView that I’d like to set an adapter on. Before I switched to using Fragments, I would simply find the GridView by Id and then set the adapter. For reasons I don’t currently understand, the GridView is null when I try finding it by Id in my FragmentsActivity.
So, I’d like to set the adapter in the fragment itself. I’m assuming I need to do this in onActivityCreated, but I don’t know how I’ll set the adapter on the GridView that’s contained within the View being returned by onCreateView. In other words, how do I grab hold of that View that’s returned by onCreateView to set the Adapter on it?
EDIT – I just realized, I could probably just find the GridView in onActivityCreated and set the adapter there, no?
You created the
GridViewin the fragment inonCreateView(). Just hold onto it in a data member of the fragment.