简体   繁体   中英

Fragment onStart Activated without being in current Fragment

I have TabLayout using 4 fragment, a1, a2, a3, a4, The problem is when I enter a1 Fragment, a2 Fragment activated too, and when I go to a2 Fragment it already Activated, it seems like this => a1(Entered>Activated) - a2 (Activated) - a3(Not Activated) - a4 (Not Activated) Another case: a1(Not Activated) - a2 (Activated) - a3(Entered>Activated) - a4 (Activated) It's hard to explain it, I think my code is working properly, and why I have an issue like this, how to fix it?

override setUserVisibleHint to check if fragment activated

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if (isVisibleToUser) {

            //this Fragment is visible 

        } else {

            //this Fragment is invisible

        } 
    }

Well, I don't see exactly what is the error.

The code is working as it should be. When you are using TabLayout, the two adjacent fragments to the one selected are activated as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM