That's certainly another solution. However, you need to be careful about
future updates of that component. You never know what might change.
The caching approach would roughly look like as follows:
public abstract class MyFragmentPagerAdapter extends
> FragmentStatePagerAdapter {
> final private SparseArray<Fragment> fragments;
>
> public MyFragmentPagerAdapter(FragmentManager fm) {
> super(fm);
> fragments = new SparseArray<Fragment>();
> }
>
> @Override
> public void destroyItem(ViewGroup container, int position, Object
> object) {
> super.destroyItem(container, position, object);
> fragments.remove(position);
> }
>
> @Override
> public Fragment getItem(int position) {
> // Here is the caching
> Fragment f = fragments.get(position);
> if(f != null) return f;
>
> // ELSE:
> // Create fragment for current position
> // and cache it with
> // fragments.put(position, f);
>
> return f;
> }
> }
>
If your fragment is currently visible it will be cached in your adapter.
You can then just use your adapter to get the correct fragment instance.
On Tuesday, January 29, 2013 8:51:52 AM UTC-6, dashman wrote:
>
>
> After looking the src - finally "solved" the issue.
>
> The problem is when the fragment is stored by the pager -
> it uses the pager id and creates it's own tag.
>
> but the tag format should be stable.
>
> In your FragmentActivity if you call this method with the id of the
> Fragment -
>
> String getFragmentTag( int id )
> {
> return "android:switcher:" + mViewPager.getId() + ":" + id;
> }
>
> then this should work
>
> FragmentManager fm = getSupportFragmentManager();
>
> int id = 1; // this is the id of the Fragment child you add
> via the adapter
>
> Fragment fr = fm.findFragmentByTag( getFragmentTag( id ) );
>
>
>
--
--
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/groups/opt_out.