hrsetyono
hrsetyono

Reputation: 4464

Android - Need help for Tabs+Swipe template in SDK 20

I really like the template for Tabs+Swipe. You know...this one:

enter image description here

The problem is, I do not know where to start after creating that template. How to put a layout into each tab page?

Can we do something like call a Class when the tab is selected? So I can store the view for first tab in Class A then second tab in Class B.

I cannot found any information about this in Google, maybe because it is a new feature from Android SDK?

Thanks

Upvotes: 3

Views: 3801

Answers (2)

Klinetel
Klinetel

Reputation: 302

Is it possible you can place an an example of activity switching between tabs? The example above isn't ideal.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007349

How to put a layout into each tab page?

The generated code creates a ViewPager in the layout file and wires up action bar tabs to the pages in that ViewPager. Personally I'd rather use a PagerTabStrip, or possibly one of the ViewPagerIndicator equivalents, but they didn't ask me... :-)

Regardless, to fill in the pages, you need to replace (or complete) the SectionsPagerAdapter and/or DummySectionFragment inner classes of the generated activity. Right now, this is set up to have three pages, each of which is merely a TextView. But, you could have DummySectionFragment inflate a layout instead, and if you are looking for different layouts per tab, you would probably create separate Fragment implementations per layout/tab combination. You would then teach SectionsPagerAdapter how many pages you want (getCount()) and what to use for each page (getItem()) and what each tab caption is (getPageTitle()).

Upvotes: 3

Related Questions