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 8057777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:08:42+00:00 2026-06-05T09:08:42+00:00

I am developing an app in Android 4 . I have three tabs in

  • 0

I am developing an app in Android 4. I have three tabs in my app. What my requirement is, I want to show only 1st tab in the beginning, and after clicking on some button from tab 1, I want to show 2nd Tab, after clicking on button, the 3rd tab will be visible.

As Tabs in Android 3 on-wards, does not have setVisibility method, Please tell me how to show/hide particular tab in my case.

Any help will be appreciated.

Thank you.

UPDATE: onClick of button, I have added this code:

ActionBar actionbar = getActivity().getActionBar();
                ActionBar.Tab Tab2 = actionbar.newTab().setText("XYZ");
                ActionBar.Tab Tab3 = actionbar.newTab().setText("PQR");

                Fragment Tab2Fragment = new BFragment();
                Fragment Tab3Fragment = new CFragment();

                Tab2.setTabListener(new MyTabsListener(Tab2Fragment));
                Tab3.setTabListener(new MyTabsListener(Tab3Fragment));
                actionbar.addTab(Tab2);
                actionbar.addTab(Tab3);

But still its not working..

UPDATE: Now I can see two tabs coming, but I am getting NPE:

06-08 20:57:58.101: E/AndroidRuntime(17070): java.lang.NullPointerException

06-08 20:57:58.101: E/AndroidRuntime(17070):    at de.arvidg.exampleactionbartabs.AFragment.onActivityCreated(AFragment.java:116)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:847)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.app.BackStackRecord.run(BackStackRecord.java:622)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.os.Handler.handleCallback(Handler.java:605)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.os.Looper.loop(Looper.java:137)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at java.lang.reflect.Method.invokeNative(Native Method)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at java.lang.reflect.Method.invoke(Method.java:511)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-08 20:57:58.101: E/AndroidRuntime(17070):    at dalvik.system.NativeStart.main(Native Method)

This is my onCreateView and onActivityCreated in AFragment are:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.afragment, container, false);
    }

/* (non-Javadoc)
     * @see android.app.Fragment#onActivityCreated(android.os.Bundle)
     */
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        appContext = AFragment.this;
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter == null) {
            Toast.makeText(getActivity(), "NO Bluetooth Available", Toast.LENGTH_LONG);
            getActivity().finish();
            return;
        }
        final Button connectBtn = (Button) getActivity().findViewById(R.id.connect_btn);
        connectBtn.setClickable(true); // NPE is occurring 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-05T09:08:43+00:00Added an answer on June 5, 2026 at 9:08 am

    use ActionBar.addTab() to add tabs, ActionBar.removeTabAt() to remove a tab. Also, ActionBar.getTabCount() can be used to determine the current number of tabs configured.

    ActionBar actionBar = this.getActionBar();
    if (actionBar.getTabCount() == 1)
    {
     // 2nd tab
     MyFragment fragment = new MyFragment();
     ActionBar.Tab tab2nd = actionBar.newTab();
     tab2nd.setTabListener(fragment);
     actionBar.addTab(tab2nd);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android app and I want to show japanese kanji on it,
I started developing an android app that have to interact with MMS attachements, in
I'm developing an android app, and I need to have a json response of
Hello everyone i am developing an quiz based app in android and i have
I have a Titanium Android app that I'm developing and recently deployed to the
Iam developing an android app.about google maps API for android i want to ask
I am developing an android app. for mathematical calculations. There I have some buttons
I'm developing an app for Android 2.1 upwards. I want to enable my users
I have been developing an Android app and testing with a 1.5 AVD and
I have basically finished developing an android app that makes use of SQLite databases

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.