I use ActionBarSherlock and use this template to navigate the tab that I found on the Android developer site. It works very well, but I also want to switch between NAVIGATION_MODE_TABSand NAVIGATION_MODE_LISTwhile maintaining the connection between tabs and fragments.
The template mentioned above is pretty good for maintaining common code. Therefore, I add listeners to my tabs and associate them with snippets such as this:
bar.addTab(bar.newTab()
.setText("MyFragment")
.setTabListener(new TabListener<SomeFragment>(this, "myfargment", SomeFragment.class)));
and create an instance of the fragment by clicking on the corresponding tab using generics:
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mFragment == null) {
mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
ft.add(android.R.id.content, mFragment, mTag);
} else {
ft.attach(mFragment);
}
}
, , . , OnNavigationListener ActionBar , .
- :
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
switch (itemPosition) {
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
return true;
}
EDIT:
:
NAVIGATION_MODE_TABS, , (, ), , ?