Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load different activities in tabs

Tags:

android

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.

like image 483
rkmax Avatar asked Feb 18 '23 03:02

rkmax


2 Answers

You should use Tabs with Fragments.

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

like image 183
Pablo Martinez Avatar answered Feb 27 '23 14:02

Pablo Martinez


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.

like image 39
fedepaol Avatar answered Feb 27 '23 13:02

fedepaol