Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why I can't add a instance of Fragment? #12

Closed
ppamorim opened this issue Apr 22, 2015 · 10 comments
Closed

Why I can't add a instance of Fragment? #12

ppamorim opened this issue Apr 22, 2015 · 10 comments
Labels

Comments

@ppamorim
Copy link

This can be a problem:

add(int title, java.lang.Class<? extends android.support.v4.app.Fragment> clazz)

I need to have a:

add(int title, Fragment fragment)

Why, If I need create a instance of the Fragment, I need use this.

@ogaclejapan
Copy link
Owner

Hi, @ppamorim

Should use the v13 of utility.

//Optional: see how to use the utility.
compile 'com.ogaclejapan.smarttablayout:utils-v13:1.1.1@aar'

@ogaclejapan
Copy link
Owner

Sorry mistake.
Do not support because unnecessary instance.

@ppamorim
Copy link
Author

@ogaclejapan Based on what you said that?

@ogaclejapan
Copy link
Owner

Hi, @ppamorim
Fragment instance repeat creation and destruction on the ViewPager.
So, I think it is better to use the Fragment.instantiate(...) rather than give an instance.

@ppamorim
Copy link
Author

You're wrong.
Only the view will be recreate, not a instance of the fragment.
I use the instance of the Fragment a long time on my applications.

@ogaclejapan
Copy link
Owner

Please try checked Don’t keep activities in the developer mode.
When you view again after returning to the home, it will change to a different instance.
Often occurs is similar events in low memory device.

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Object item = super.instantiateItem(container, position);
        Log.d("DEBUG", "position: " + position + " " + item.toString());
        if (item instanceof Fragment) {
            mHolder.put(position, new WeakReference<Fragment>((Fragment) item));
        }
        return item;
    }

@ppamorim
Copy link
Author

@ogaclejapan
Copy link
Owner

Hi, @ppamorim
Thank you upload the code.

What are the reasons why you think you have the better of this code than the current implementation?
I think enough in the current implementation to be instantiated when needed.

The library utility that provides adapters is optional,
if you want to use the adapter that you have pre-instantiation, please use to implement yourself.

Although I'm sorry,
Function to add a pre-instantiated fragment does not have plans to add to the utility.

@ppamorim
Copy link
Author

How to do this?

@ppamorim
Copy link
Author

Solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants