I\'m trying to get a View from GridView. Unfortunately, it returns null
.
onCreate():
GridView gridview = (GridView) fin
GridView
will populate itself from the adapter during the first layout pass. This means it won't have children in onCreate()
. The easiest way to wait for the first layout pass is to use a ViewTreeObserver
(see View.getViewTreeObserver()
) to register a global layout listener. The first time the listener is invoked, the grid should contain children.
Note that if you want to change the background of one of the children of a GridView
you really should do it from the adapter. Since views are recycled the background may appear to "move" to another view later on.