Frage

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?

War es hilfreich?

Lösung

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 {
        ...
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top