0

I have a couple of fragments in a viewpager and each time their onViewCreated() is called I set the adapter unless it has already been set.

I check this by

getListAdapter() == null ? setAdapter() : //Otherwise do nothing

This works great. However when I have a GridView instead of the ListView and I perform the same actions, the adapter is always null so it needs to be set each time the fragment is created. Why is this?

mGridView.getAdapter() == null ? setAdapter() : //Otherwise do nothing
mmBs
  • 8,421
  • 6
  • 38
  • 46
zoltish
  • 2,122
  • 19
  • 37
  • This seems totally normal. Of course after the View has been created it won't by default have an adapter, unless you've already created one and are retaining it across configuration changes. When are you initially setting the adapter? `onCreate()`? – Kevin Coppock Sep 08 '13 at 21:30
  • @kcoppock I set the adapter in onViewCreated() and create it in onCreate()(onCreate is only called the first time it is created). And it seems that the adapter stays, even if the view is swiped far enough off-screen. – zoltish Sep 09 '13 at 06:29

0 Answers0