开发者

How to correctly create a Tablayout now that the Tabactivity is deprecated?

Since the introduction of Fragments the TabActivity is deprecated.

The Hello Views TabLayout Tutorial however still uses the TabActivity and the API-Documentation has no clear answer on how to create a Tab Layout with Fragments instea开发者_Go百科d of a TabActivity.

How are you building Tablayouts now that the TabActivity is deprecated?


Well, I had that issue and here is the solution example for that FragmentTabs.java. But I am still awaiting for the solution that Fragments provides instead of using ActivityGroup.


Use TabHost or ActionBar with tabs along with Fragments .

I recommend you to use ActionBar with tabs and a ViewPager to hold the fragments for each tabs.

in onPageSelected() of onPageChangeListener, set the current tab by getActionBar().setSelectedNavigationItem(position);

and in onTabSelected(Tab tab, FragmentTransaction ft) of TabListener set the current page in viewpager by mViewPager.setCurrentItem(tab.getPosition());

Check this example too. Good Luck!


Since the release of ActionBarSherlock there is no need to use the old tap API. Just use the new tabs with fragments in any way you like on any recent Android Version (2.x)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜