Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:02:02+00:00 2026-06-08T02:02:02+00:00

I have successfully implemented actionsherlock in my project.so here is my code: public class

  • 0

I have successfully implemented actionsherlock in my project.so here is my code:

public class ActiontabActivity extends SherlockFragmentActivity   {


    ActionMode mMode;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);
        setContentView(R.layout.main);
         ActionBar bar = getSupportActionBar();
            bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
            bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

            bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

            bar.setDisplayShowHomeEnabled(false);


            bar.setDisplayShowTitleEnabled(false);
            bar.setTitle("Currency Exchange");
            bar.addTab(bar
                    .newTab()
                    .setText("Converter")
                    .setTabListener(
                            new TabListener<Fragment>(this, "Converter",
                                    ConverterTab.class, null)));

            bar.addTab(bar
                    .newTab()
                    .setText("Favorites")
                    .setTabListener(
                            new TabListener1<Fragment>(this, "Favorites",
                                    FavoritesTab.class, null)));
            if (savedInstanceState != null) {
                bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
            }


    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("tab", getSupportActionBar()
                .getSelectedNavigationIndex());
    }

    public class TabListener<T extends Fragment> implements ActionBar.TabListener {
        private final FragmentActivity mActivity;
        private final String mTag;
        private final Class<ConverterTab> mClass;
        private final Bundle mArgs;
        private Fragment mFragment;




        public TabListener(FragmentActivity activity, String tag, Class<ConverterTab> clz, Bundle args) {
            mActivity = activity;
            mTag = tag;
            mClass = clz;
            mArgs = args;
            FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();


            // Check to see if we already have a fragment for this tab, probably
            // from a previously saved state.  If so, deactivate it, because our
            // initial state is that a tab isn't shown.
            mFragment = mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
            if (mFragment != null && !mFragment.isDetached()) {
                ft.detach(mFragment);
            }
        }




        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
             ft = mActivity.getSupportFragmentManager()
                        .beginTransaction();

                if (mFragment == null) {
                    mFragment = Fragment.instantiate(mActivity, mClass.getName(),
                            mArgs);
                    ft.add(android.R.id.content, mFragment, mTag);
                    ft.commit();
                } else {
                    ft.attach(mFragment);
                    ft.commit();
                }


        }




        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
               if (mFragment != null) {
                    //this segment removes the back history of everything in the tab you are leaving so when you click on the tab again you go back to a fresh start
                    FragmentManager man = mFragment.getFragmentManager();
                    if(man.getBackStackEntryCount()>0) //this check is required to prevent null point exceptions when clicking off of a tab with no history
                        man.popBackStack(man.getBackStackEntryAt(0).getName(), FragmentManager.POP_BACK_STACK_INCLUSIVE); //this pops the stack back to index 0 so you can then detach and then later attach your initial fragment
                    //also it should be noted that if you do popbackstackimmediate here instead of just popbackstack you will see a flash as the gui changes back to the first fragment when the code executes
                    //end
                    ft.detach(mFragment);
                }



        }




        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }



    }
    public class TabListener1<T extends Fragment> implements ActionBar.TabListener {
        private final FragmentActivity mActivity;
        private final String mTag;
        private final Class<FavoritesTab> mClass;
        private final Bundle mArgs;
        private Fragment mFragment;




        public TabListener1(FragmentActivity activity, String tag, Class<FavoritesTab> clz, Bundle args) {
            mActivity = activity;
            mTag = tag;
            mClass = clz;
            mArgs = args;
            FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();


            // Check to see if we already have a fragment for this tab, probably
            // from a previously saved state.  If so, deactivate it, because our
            // initial state is that a tab isn't shown.
            mFragment = mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
            if (mFragment != null && !mFragment.isDetached()) {
                ft.detach(mFragment);
            }
        }




        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
             ft = mActivity.getSupportFragmentManager()
                        .beginTransaction();

                if (mFragment == null) {
                    mFragment = Fragment.instantiate(mActivity, mClass.getName(),
                            mArgs);
                    ft.add(android.R.id.content, mFragment, mTag);
                    ft.commit();
                } else {
                    ft.attach(mFragment);
                    ft.commit();
                }


        }




        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
             if (mFragment != null) {
                    //this segment removes the back history of everything in the tab you are leaving so when you click on the tab again you go back to a fresh start
                    FragmentManager man = mFragment.getFragmentManager();
                    if(man.getBackStackEntryCount()>0) //this check is required to prevent null point exceptions when clicking off of a tab with no history
                        man.popBackStack(man.getBackStackEntryAt(0).getName(), FragmentManager.POP_BACK_STACK_INCLUSIVE); //this pops the stack back to index 0 so you can then detach and then later attach your initial fragment
                    //also it should be noted that if you do popbackstackimmediate here instead of just popbackstack you will see a flash as the gui changes back to the first fragment when the code executes
                    //end
                    ft.detach(mFragment);
                }


        }




        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }



    }
}

And i put one button in converter tab and one checkbox in favorites tab.But now i want when i run my app its initially not selected any tab.Just show the main screen and when i pressed any tab it shows it’s contents.Because initially i wanted to show other contents when no tab is selected.please tell me how can i do this?Please give me idea that how can i show initially main screen and then when i select any tab it shows its contents.I have attached image of my project:

enter image description here enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:02:03+00:00Added an answer on June 8, 2026 at 2:02 am

    You can do this in the following way:

    bar.addTab(yourTab,false);
    

    Like this the tab is still visual selected but the action in the method onTabSelected in listener is not executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully implemented a network application in visual CLR project using boost.asio. but
I have successfully implemented slider to my Cocos2D project using this resource . The
I have successfully implemented face detection part in my Face Recognition project.Now i have
I have successfully implemented code to plot multiple locations on google maps dynamically. Solution:
I have successfully implemented django-ajax-uploader into my project. But I do not know how
I have successfully implemented the WCF callback pattern in my code and now I
I have implemented successfully this code: Does anyone know how to write an Apple
I have successfully implemented facebook connect plugin in android phonegap project with help of
I have successfully implemented i18n in my project. Now I'm stuck in my Bean...
I have successfully implemented a mysql server as a JDBCRealm for authentication in Tomcat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.