SOLVED! After tracing the execution through ViewPager and 
FragmentPagerAdapter and trying to explain the very strange behavior I was 
seeing, I eventually discovered that when I wrote my fragments extending 
Fragment and ListFragment a long time ago, I had added a getView() method 
that was (inadvertently) overriding the method by that name in the 
superclass and was returning the wrong view for what the ViewPager was 
expecting. I removed these methods and everything started working.

The only explanation I have for why this code was working OK with the 
native fragments is that I noticed that the support.v4 fragments enclose 
the fragment's actual root view as returned by onCreateView with some sort 
of FrameLayout that they create, and that is what getView returns. The 
native fragments apparently do not do this, so the view returned by my 
getView method worked correctly.

The only odd thing, and I am not a Java expert, is that I did not precede 
my getView with @Override and did not notice any error or warning about 
that. Isn't this required? I know that when I wrote that code that I was 
not intending to override the superclass.

On Saturday, December 20, 2014 1:04:23 PM UTC-5, Kostya Vasilyev wrote:
>
> Ok, so the items are there and the views are there.
>
> What I would do at this point is check the attributes (data) of those 
> views:
>
> - Their positions and sizes
> - Visibility
> - Animation state
> - Translation / scaling
> - Scroll positions
>
> Or I would try to debug into the view pager's onMeasure / onLayout / 
> populate + scrollToItem
>
> For this second part, I would perhaps add a button in the layout that 
> calls requestLayout or setCurrentItem on the pager, to trigger as needed.
>
> -- K
>
> 2014-12-20 17:17 GMT+03:00 Doug Gordon <gord...@gmail.com <javascript:>>:
>
>> Kostya, I have done that and what I am seeing is the background of the 
>> ViewPager, but not my fragments' views. I set a breakpoint so I could go 
>> back into the ViewPager, and examining its data structure I find that not 
>> only does its mItems array contain my instantiated fragments, but also the 
>> mChildren array in the base View contains my fragments' expanded view 
>> hierarchies!
>>
>> There is just something that is preventing the views from being drawn, 
>> even if I explicitly call invalidate() on the ViewPager. And it still seems 
>> that it must have something to do with using the support.v4 fragment 
>> support since it all works fine using native fragments.
>>
>> On Friday, December 19, 2014 4:57:43 PM UTC-5, Kostya Vasilyev wrote:
>>>
>>> Have you tried debugging into ViewPager code?
>>>
>>> To see if your fragments' views are actually there and how they're laid 
>>> out?
>>>
>>> Another thing I often use in cases like this -- is to set the background 
>>> color of various views to distinct noticeable colors, like pink, cyan, etc. 
>>> In this case, I'd try the view pager itself, its parent view, and your 
>>> fragments' views.
>>>
>>> -- K
>>>
>>> 2014-12-20 0:30 GMT+03:00 Doug Gordon <gord...@gmail.com>:
>>>
>>>> I haven't received any responses on stackoverflow about this, so am 
>>>> giving it a shot here.
>>>>
>>>> My app, which is fairly large and complex (hard to post meaningful 
>>>> code) uses as its main view a ViewPager with a FragmentPagerAdapter. Since 
>>>> the minSDK is 14, I originally wrote it to use the native Fragment and 
>>>> related classes (ViewPager from support.v4 and FragmentPagerAdapter from 
>>>> support.v13). This has all been working perfectly for a long time.
>>>>
>>>> Recently I decided to build in more compatibility, mainly for themes, 
>>>> by using the appcompat.v7 library. However, using this library required 
>>>> that I use the Fragment and FragmentPagerAdapter, etc. classes from the 
>>>> support.v4 library (meaning that I also had to change my Activity to a 
>>>> FragmentActivity, call getSupportFragmentManager, etc.).
>>>>
>>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to