On Sunday, December 21, 2014 6:15:44 AM UTC+3, Doug Gordon wrote:
>
> 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.
>

@Override is not required. 

It's for flagging a method that you intend to be an override -- and if it 
really isn't (no matching method in a base class / interface), then the 
compiler will flag it with an error.

Useful to detect a situation when someone makes a change to a base class or 
interface (potentially a few hierarchy levels up), maybe adding a 
parameter, that sort of thing -- and your class' method suddenly doesn't 
override what it's supposed to, breaking at runtime.

Personally, I find it very useful to use Eclipse's "auto-format when 
saving", with the setting that automatically adds any missing @Override 
annotations.

-- K

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to