简体   繁体   中英

Create fragments, for older versions of android

How can I use fragments, in older versions of android. For android HoneyComb and early I write this code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        FragmentManager fragmentManager = getFragmentManager();

        Fragment menuFragment = new MenuFragment();
        fragmentManager.beginTransaction().replace(R.id.topMenu, menuFragment).commit();

        Fragment contentFragment = new AlleFragment();
        fragmentManager.beginTransaction().replace(R.id.container, contentFragment).commit();   
    }

But I don't know how to write this code to run for older version of android. Can someone to help me?

You can include support library v4 which comes with Android SDK. You have example in official Android documentation: http://developer.android.com/training/basics/fragments/creating.html

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