Saturday, February 9, 2013

Re: [android-developers] Re: onCreateOptionsMenu being hit too many times

Oh, I gotcha.  I see where I'm wrong, instead of creating a collection of Fragments, I should create a collection of id's and do something like this in getItem():

      @Override 
        public Fragment getItem(int index) {
           
            if (index == 0)
                return MyListFragment.newInstance();
            else               
                return MyDetailFragment.newInstance(id.get(index));
        } 

On Saturday, February 9, 2013 5:31:07 PM UTC-5, Mark Murphy (a Commons Guy) wrote:
The tutorial you link to does what I described: it creates the
fragments on demand from getItem() of the adapter.

On Sat, Feb 9, 2013 at 5:22 PM, FiltrSoft <kri...@gmail.com> wrote:
> So, should I re-think how I'm setting up my ViewPager?  This is the first
> time I've implemented one, so I was a little in the dark on the best
> practices.
>
> I was using this tutorial as base for what I needed to do:
> http://tamsler.blogspot.com/2011/10/android-viewpager-and-fragments.html
>
>
> On Saturday, February 9, 2013 4:56:57 PM UTC-5, Mark Murphy (a Commons Guy)
> wrote:
>>
>> Well, normally, you don't even need to do that.
>> FragmentPagerAdapter/FragmentStatePagerAdapter use the tag to
>> determine what fragment goes in what page. So your pages will
>> automatically reappear after the configuration change. This is why
>> most samples do not do what you are doing, creating fragments in the
>> activity and forcing them into the adapter. Instead, the adapter
>> creates fragments *on demand* only when needed in the call to
>> getItem().
>>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-d...@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@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+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 4.5 Available!

--
--
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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment