简体   繁体   中英

load different activities in tabs

It took quite a while searching stackoverflow and google and can not find a guide to properly explain to me how to implement Tabs in my application.

I know it should not be used TabActivity, I also read about the recommendation not to use TabHost (at least that understanding). My interest is not just changing the content is run a full activity when changing tab.

Example

MainActivity:
   - Tab1Activity
   - Tab2Activity
   - Tab3Activity

My goal is to build an application that is supported by a wide range of devices from api 8 to the latest. I'm using android-support-v4.jar .

My second goal is to load in each tab an activity because at least two of them consume enough resources and speed should always prevail.

Can help me with a guide or explain a "correct" way to achieve this.

You should use Tabs with Fragments.

Look this : http://android.codeandmagic.org/2011/07/android-tabs-with-fragments/

As the other suggested, the best way to implement tabs in your application is to use fragments.

You should not use activities contained in a tabactivity, which is currently deprecated. Even the official documentation suggests to use fragments , stating that

New applications should use Fragments instead of this class

However, if you still feel retro' and you REALLY want to use tab contained activities, you need to use tabhost. A nice tutorial can be found here , but again, I strongly recommend to go for the fragment way.

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