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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:56:35+00:00 2026-06-11T17:56:35+00:00

I am having trouble determining whether or not a certain tab has been selected

  • 0

I am having trouble determining whether or not a certain tab has been selected in the navigation bar. I am trying to determine if the ingredient tab has been selected. Every time I run my code it returns that there is a null pointer error because mFragment is null and has not been instantiated.

Ok… I understand that mFragment is null. I guess this is where I am getting confused. When comparing fragments are you comparing their content or the object itself? And if anyone knows how to compare fragments that would be great. Thank you in advance. Here is the code:

public static class TabListener<T extends Fragment> implements ActionBar.TabListener {
    private final Activity mActivity;
    private final String mTag;
    private final Class<T> mClass;
    private final Bundle mArgs;
    private Bundle mTitleArgs;
    private Fragment mFragment;
    private IngredientCreation ingredientFrag;
    private FragmentTabControl controller;

    public TabListener(Activity activity, String tag, Class<T> clz) {
        this(activity, tag, clz, null);
    }

    public TabListener(Activity activity, String tag, Class<T> clz, Bundle args) {
        mActivity = activity;
        mTag = tag;
        mClass = clz;
        mArgs = args;

        // 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.getFragmentManager().findFragmentByTag(mTag);
        if (mFragment != null && !mFragment.isDetached()) {
            FragmentTransaction ft = mActivity.getFragmentManager().beginTransaction();
            ft.detach(mFragment);
            ft.commit();
        }
    }

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ingredientFrag = (IngredientCreation) mActivity.getFragmentManager().findFragmentByTag("ingredients");

        if (mFragment.equals(ingredientFrag)) {

            System.out.println("got here");
            mFragment = Fragment.instantiate(mActivity, mClass.getName(), mTitleArgs);
            ft.add(android.R.id.content, mFragment, mTag);
        } else {
            ft.attach(mFragment);
        }
    }
  • 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-11T17:56:36+00:00Added an answer on June 11, 2026 at 5:56 pm

    The documentation on the ActionBar has a good example of how to properly create a Tab Listener. Checkout this link for a good implementation. http://developer.android.com/guide/topics/ui/actionbar.html

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

Sidebar

Related Questions

I was having trouble determining what was cause my form to not submit when
I am having trouble determining why my code gets a nullPointer exception. I'm trying
I'm having trouble determining if it's possible, based on the amount of access I
After my page loads my text disappears and I am having trouble determining why.
I am having some trouble determining if two line segments are collinear because of
Having trouble framing this assertion in Rspec for my rails app. A User has
I'm having trouble determining the best way to read some input in for a
Having trouble determining if a file name conforms to a specific convention as follows.
I'm having trouble determining the difference between CREATE SCHEMA and CREATE DATABASE. I'm of
My Perl isn't very good at all and I am having trouble determining why

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.