Android detect selected tab and change ActionBar - android

Hi i have an an ActionBar that contains a TabBar and on each tab i want to change the actionbar title/icon based on which tab is selected. How do i detect which tab i'm on and run an if statement for example if tab = tab1 then set actionbar title?
heres my activity
ActionBar actionbar = getActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
getActionBar().setTitle("");
getActionBar().setIcon(R.drawable.ab_logo);
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000")));
actionbar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#eeeeee")));
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View tabView = inflater.inflate(R.layout.tab_3, null);
ActionBar.Tab Tab1 = actionbar.newTab().setIcon(R.drawable.ic_tab_1);
ActionBar.Tab Tab2 = actionbar.newTab().setIcon(R.drawable.ic_tab_2);
ActionBar.Tab Tab3 = actionbar.newTab().setCustomView(tabView);
ActionBar.Tab Tab4 = actionbar.newTab().setIcon(R.drawable.ic_tab_4);
ActionBar.Tab Tab5 = actionbar.newTab().setIcon(R.drawable.ic_tab_5);
Fragment Fragment1 = new Fragment1();
Fragment Fragment2 = new Fragment2();
Fragment Fragment3 = new Fragment3();
Fragment Fragment4 = new Fragment4();
Fragment Fragment3 = new Fragment5();
Tab1.setTabListener(new MyTabsListener(Fragment1));
Tab2.setTabListener(new MyTabsListener(Fragment2));
Tab3.setTabListener(new MyTabsListener(Fragment3));
Tab4.setTabListener(new MyTabsListener(Fragment4));
Tab5.setTabListener(new MyTabsListener(Fragment5));
actionbar.addTab(Tab1);
actionbar.addTab(Tab2);
actionbar.addTab(Tab3);
actionbar.addTab(Tab4);
actionbar.addTab(Tab5);
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
}
}
heres my TabListener Class
public class TabListener implements ActionBar.TabListener {
public Fragment fragment;
public Context c;
public ActionBar actionbar;
public TabListener(Fragment fragment, Context con) {
this.fragment = fragment;
this.c = con;
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
}

You could also do this in your onTabSelected method
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
switch (tab.getPosition()) {
case 1:
actionbar.setTitle("new title");
actionbar.setIcon(iconDrawable);
break;
case 2:
actionbar.setTitle("new title");
actionbar.setIcon(iconDrawable);
break;
}
}

You can do this in each fragment:
private ActionBar actionBar;
in onActivityCreated:
actionBar = ((ActionBarActivity)getActivity()).getSupportActionBar();
in fragment onCreateView method
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
setHasOptionsMenu(true);
return rootView;
}
then in onCreateOptionsMenu(Menu menu, MenuInflater inflater) method
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
// Clear old menu.
menu.clear();
// Inflate new menu.
inflater.inflate(R.menu.your_fragment_menu, menu);
// Set actionbar title and icon.
actionBar.setTitle("your fragment title");
actionBar.setIcon(R.drawable.ic_fragment);
}
Hope this answer help you.

Related

Third tab is not shown on actionbar with fragments

I want to create an app with three tabs. I have three fragments, three xml files, one main activity, one main xml and a tablistener class. The app shows the first two tabs properly, but the third tab is not shown. There is no error in the code.
Note: I'm using support library.
MainActivity:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupTabs();
}
// To setup tabs using ActionBar and fragments
private void setupTabs() {
// setup the ActionBar
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(true);
//define which tabs you would like to display
//and attach listeners for each tab:
ActionBar.Tab tab1 = actionBar
.newTab()
.setText("First")
.setTabListener(new SupportFragmentTabListener<FirstFragment>(R.id.main,this,
"first", FirstFragment.class));
actionBar.addTab(tab1);
actionBar.selectTab(tab1);
ActionBar.Tab tab2 = actionBar
.newTab()
.setText("Second")
.setTabListener(new SupportFragmentTabListener<SecondFragment>(R.id.main,this,
"second", SecondFragment.class));
actionBar.addTab(tab2);
ActionBar.Tab tab3 = actionBar
.newTab()
.setText("Third")
.setTabListener(new SupportFragmentTabListener<ThirdFragment>(R.id.main, this,
"third", ThirdFragment.class));
ActionBar.Tab tab4 = actionBar
.newTab()
.setText("Fourth")
.setTabListener(new SupportFragmentTabListener<FourthFragment>(R.id.main, this,
"fourth", FourthFragment.class));
}
}
TabListener:
public class SupportFragmentTabListener<T extends Fragment>
implements TabListener {
private Fragment mFragment;
private final FragmentActivity mActivity;
private final String mTag;
private final Class<T> mClass;
private final int mfragmentContainerId;
public SupportFragmentTabListener(FragmentActivity activity, String tag, Class<T> clz) {
mActivity = activity;
mTag = tag;
mClass = clz;
mfragmentContainerId = android.R.id.content;
}
public SupportFragmentTabListener(int fragmentContainerId, FragmentActivity activity, String tag, Class<T> clz) {
mActivity = activity;
mTag = tag;
mClass = clz;
mfragmentContainerId = fragmentContainerId;
}
/* The following are each of the ActionBar.TabListener callbacks */
public void onTabSelected(Tab tab, FragmentTransaction sft) {
// Check if the fragment is already initialized
if (mFragment == null) {
// If not, instantiate and add it to the activity
mFragment = Fragment.instantiate(mActivity, mClass.getName());
sft.replace(mfragmentContainerId, mFragment, mTag);
} else {
// If it exists, simply attach it in order to show it
sft.replace(mfragmentContainerId, mFragment);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction sft) {
if (mFragment != null) {
// Detach the fragment, because another one is being attached
//sft.remove(mFragment);
sft.replace(mfragmentContainerId,mFragment);
}else{
// If not, instantiate and add it to the activity:
mFragment = Fragment.instantiate(mActivity, mClass.getName());
sft.add(android.R.id.content, mFragment,mTag);
}
}
public void onTabReselected(Tab tab, FragmentTransaction sft) {
// User selected the already selected tab. Usually do nothing.
}
}
ThirdFragment:
public class ThirdFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.grade_table, container, false);
TextView ff = (TextView) rootView.findViewById(R.id.textView2);
return rootView;
}
}
You need to add the tab after creating it. You forgot to write:
actionBar.addTab(tab3);
and
actionBar.addTab(tab4);

Navigation drawer with tabs in fragment

I am making an android app . I am using navigation drawer and some of the fragments which i am inflating using navigation drawer contain tab layout and some are normal fragments with textview .
I am facing 2 issues that when
i am opening the navigation drawer item with tabs afterthat its automatically keeping those tabs in the view even for the fragments that are not with tabs.
When i am opening the fragment with tabs 2nd time or more . Its duplicating the tabs. I mean if the first time no of tabs are 3 then the next time when i open the fragment the no. of tabs get doubled.
Activity with navigation drawer
public class MainFeedActivity extends FragmentActivity {
public DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mDrawertitles;
LinearLayout drawerll;
String username;
TextView t;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainfeed);
username = getIntent().getExtras().getString("username").toString();
t = (TextView) findViewById(R.id.drawer_uname_tv);
t.setText(username);
mTitle = mDrawerTitle = getTitle();
mDrawertitles = getResources().getStringArray(R.array.array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
drawerll = (LinearLayout) findViewById(R.id.drawerll);
// set a custom shadow that overlays the main content when the drawer
// opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mDrawertitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
getActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open,
R.string.drawer_close) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(2);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return true;
}
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
selectItem(position);
}
}
private void selectItem(int position) {
if (position == 0) {
Fragment fragment = new Home();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mDrawerLayout.closeDrawer(drawerll);
}
else if (position == 1) {
Fragment fragment = new Statistics();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerLayout.closeDrawer(drawerll);
} else {
Fragment fragment = new Help();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
// update selected item and title, then close the drawer
mDrawerLayout.closeDrawer(drawerll);
}
}
/*
*
* protected boolean isOnline() { ConnectivityManager cm =
* (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
* NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null &&
* netInfo.isConnectedOrConnecting()) { return true; } else { return false;
* } }
*/
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
/**
* Fragment that appears in the "content_frame", shows a planet
*/
}
Fragments
public class Home extends Fragment {
ActionBar.Tab Tab1, Tab2, Tab3;
Fragment fragmentTab1 = new Connected();
Fragment fragmentTab2 = new Disconnected();
Fragment fragmentTab3 = new AllDevices();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tabs, container, false);
ActionBar actionBar = getActivity().getActionBar();
actionBar.setDisplayShowHomeEnabled(true);
// Hide Actionbar Title
actionBar.setDisplayShowTitleEnabled(true);
// Create Actionbar Tabs
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab1 = actionBar.newTab().setText("Tab1");
Tab2 = actionBar.newTab().setText("Tab2");
Tab3 = actionBar.newTab().setText("Tab3");
Tab1.setTabListener(new TabListener(fragmentTab1));
Tab2.setTabListener(new TabListener(fragmentTab2));
Tab3.setTabListener(new TabListener(fragmentTab3));
actionBar.addTab(Tab1);
actionBar.addTab(Tab2);
actionBar.addTab(Tab3);
return view;
}
}
Fragments:
public class Help extends Fragment {
Button b;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.help, container, false);
setHasOptionsMenu(false);
return rootView;
}
}
I got the solution of my problems:
1st problem solved with the help of denvercoder9
when position!= 1, you need to change the actionBar Navigation Mode.... Android ActionBar: show/hide tabs dynamically? – denvercoder9
2nd problem's solution is
I need to use this
ActionBar actionBar = getActivity().getActionBar();
actionBar.removeAllTabs();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
in Home.java class
This resolved the problem of tabs duplication.
Thanks Stackoverflow for helping me :)
I was having the same issue so the solution is simple.
Ans 1: If you don't want Tabs in specific fragment then you can set the navigation bar as
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Ans 2: Either remove the tabs from the home fragment each time u select it or u can check if required tabs already present there then dont add any more tabs in it like this
int tabCount= actionBar.getTabCount();
if(tabCount!=3){
Tab1 = actionBar.newTab().setText("Tab1");
Tab2 = actionBar.newTab().setText("Tab2");
Tab3 = actionBar.newTab().setText("Tab3");
Tab1.setTabListener(new TabListener(fragmentTab1));
Tab2.setTabListener(new TabListener(fragmentTab2));
Tab3.setTabListener(new TabListener(fragmentTab3));
actionBar.addTab(Tab1);
actionBar.addTab(Tab2);
actionBar.addTab(Tab3);
}
return view;
Hope it will solve your problem

ReCreate Fragment layout

I have actionbar tabs and when a tab is clicked I want to add new button to my fragment.
This is my fragment code where I am adding buttons:
Button btn;
View myView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int numberOfButtons= getArguments().getInt("someInt",0);
LinearLayout view = new LinearLayout(getActivity());
// Inflate the layout for this fragment
view.setOrientation(LinearLayout.VERTICAL);
view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
for (int i = 0;i<numberOfButtons;i++)
{
btn = new Button(getActivity());
view.addView(new Button(getActivity()));
}
myView = view;
return myView;
}
This my MainActivity code where I am sending number of buttons to the fragment:
int numberOfButtons=0;
public static FragmentA newInstance(int someInt) {
FragmentA myFragment = new FragmentA();
Bundle args = new Bundle();
args.putInt("someInt", someInt);
myFragment.setArguments(args);
return myFragment;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
for (int i=0;i<10;i++)
{
ActionBar.Tab tab = actionBar.newTab().setText("Tab"+i).setTabListener(new ActionBar.TabListener() {
#Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
String tabText = (String)tab.getText();
String asd = (String)(tabText.substring(3,tabText.length()));
numberOfButtons = Integer.parseInt(asd);
FragmentA fragmentA = newInstance(numberOfButtons);
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.mainLayout,fragmentA,"fragA");
transaction.commit();
}
#Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
});
actionBar.addTab(tab);
}
}
This code adds buttons but there is a problem here. When Tab1 is clicked, one button is added to the fragment. When Tab2 is clicked, two buttons are added to the fragment but the first button that added by Tab1 is not removed. One of the new buttons is placed over it.
Is there any way to reset the fragment layout or remove old items of fragment before adding new ones?
From your code it seems like you're just adding the fragments' instances on top of each other.
The button added by Tab1 is not removed because Tab1 is still there in the background...
Try using the transaction.remove() method to remove the previous fragment before calling transaction.add() to add a new one...
There's also the transaction.replace() method that does both operations at the same time. Perhaps it's also worth a try.

actionbarsherlock with multiple fragments under a single tab

I created my Sherlock fragment activity and implemented tabs:
public class Home extends SherlockFragmentActivity
{
ActionBar actionBar;
TabHost myTabHost;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
actionBar=getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1= actionBar.newTab();
ActionBar.Tab tab2= actionBar.newTab();
//ActionBar.Tab tab3 = actionBar.newTab();
tab1.setText("Contacts");
tab2.setText("Inbox");
// tab3.setText("Outbox");
tab1.setTabListener(new MyTabListener());
tab2.setTabListener(new MyTabListener());
actionBar.addTab(tab1, true);
actionBar.addTab(tab2);
actionBar.addTab(tab3);
}
And this is my tab change listener:
private class MyTabListener implements TabListener
{
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if(tab.getPosition()==0)
{
FragmentA frag = new FragmentA ();
ft.replace(android.R.id.content, frag );
}
else
{
FragmentB frag = new FragmentB ();
ft.replace(android.R.id.content,frag );
}
}
And this is my FragmentA:
public class FragmentA extends Fragment
{
TextView textView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflater.inflate(R.layout.activity_list, container, false);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
}
}
Here under my first tab, there is a list that is displaying. When I click any one of the list items, I need to load another fragment under the same activity. And when back is pressed, the old fragment needs to be loaded under the same tab.
Is this possible in actionbarsherlock tabs? If so, how do I do this?

Is it possible to display tabs without using fragments in android 3.0?

Is it possible to display tabs without using fragments in android 3.0?I have created actionbar with tabs extending fragments.But without using fragments and by extending activity will i be able to display tabs.I need to achieve that.pls help.I have posted my code also.
Java Code :
public class ActionbarActivity extends Activity {
ActionBar bar;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tabA = bar.newTab().setText("Home");
ActionBar.Tab tabB = bar.newTab().setText("Listings");
ActionBar.Tab tabC = bar.newTab().setText("Remote");
Fragment fragmentA = new ATab();
Fragment fragmentB = new BTab();
Fragment fragmentC = new CTab();
bar.setDisplayShowHomeEnabled(true);
tabA.setTabListener(new MyTabsListener(fragmentA));
tabB.setTabListener(new MyTabsListener(fragmentB));
tabC.setTabListener(new MyTabsListener(fragmentC));
bar.addTab(tabA);
bar.addTab(tabB);
bar.addTab(tabC);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option, menu);
return true;
}
protected class MyTabsListener implements ActionBar.TabListener {
private Fragment mfragment;
public MyTabsListener(Fragment fragment) {
this.mfragment = fragment;
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.add(R.id.fragment_place, mfragment, null);
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
ft.remove(mfragment);
}
}
}
public class ATab extends Fragment
{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflater.inflate(R.layout.atab, container, false);
}
}
public class BTab extends Fragment
{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflater.inflate(R.layout.btab, container, false);
}
}
public class CTab extends Fragment
{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflater.inflate(R.layout.ctab, container, false);
}
}
xml.code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/fragment_place"></LinearLayout>
</RelativeLayout>
You don't have to use fragments to use tabs and I've successfully done this within one of my apps, just changing content on tab selection.
public class Main extends Activity implements ActionBar.TabListener {
int mDisplayMode;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
mDisplayMode = settings.getInt("displayMode", 0);
ActionBar actionBar = getActionBar();
actionBar.addTab(
actionBar.newTab().setText("Decimal").setTabListener(this)
);
actionBar.addTab(
actionBar.newTab().setText("Hexadecimal").setTabListener(this)
);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.selectTab(actionBar.getTabAt(mDisplayMode));
// Other code
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
mDisplayMode = tab.getPosition();
// do stuff based on new tab selected
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// do nothing
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// do nothing
}
// ..
}

Categories

Resources