Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 369
hrsetyono Avatar asked Jan 25 '26 15:01

hrsetyono


1 Answers

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()).

like image 165
CommonsWare Avatar answered Jan 28 '26 03:01

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!