简体   繁体   中英

Why public classes are in the same file in android developers swipe view example?

I know that public classes have to be in a separate file. Otherwise, they can 't be public. I try to understand and implement swipe view with titles/tabs in an android app, so I downloaded this example, which is from The Android Open Source Project. The example works and runs like a charm, but I can 't understand why, and I also can 't understand why eclipse doesn 't show me any errors for this.

If the above method is allowed in some special cases, which are these cases?

The documentation gives the impression that all classes are top level, but they are not. Check the source code on the zip file and you will see DemoCollectionPagerAdapter and DemoObjectFragment are nested inside CollectionDemoActivity .

This is the layout of the classes.

public class CollectionDemoActivity extends FragmentActivity {
    ...

    public static class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter {
        ...
    }

    public static class DemoObjectFragment extends Fragment {
        ...
    }
}

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