简体   繁体   中英

Android SherlockFragmentActivity - Tab

I use SherlockFragmentActivity and I have:

public class TestActivity extends SherlockFragmentActivity {


    private static enum Tab {
        Test1("test1", TestOneFragment.class),
        Test2("test2", TestTwoFragment.class),
        private final String title;
        private final Class<? extends Fragment> clazz;

        private Tab(String title, Class<? extends Fragment> clazz) {
            this.title = title;
            this.clazz = clazz;
        }

        private String getTitle() {
            return title;
        }

        private Class<? extends Fragment> getFragmentClass() {
            return clazz;
        }
    }

It works fine ,because I have Test1 and Test2 in the same "package".

How add external "package" class ? When I import com.bla.blaa.BlaActivity; I use this like this:

 private static enum Tab {
        Blabla("Blabla", BlaActivity.class),
        Test1("test1", TestOneFragment.class),
        Test2("test2", TestTwoFragment.class);

I have error:

The constructor TestActivity.Tab(String, Class<BlaActivity>) is 
     undefined

You cannot pass to the SherlockFragmentActivity constructor class that doesn't extend a fragment. It seems that your are trying to pass an activity (BlaActivity.class) to Tab. SherlockFragmentActivity works with fragments. You might start other application from one of the tabs using intents:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(launchIntent);

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