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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:01:16+00:00 2026-06-12T07:01:16+00:00

I am trying to implement Tab Navigation, but I want to make sure people

  • 0

I am trying to implement Tab Navigation, but I want to make sure people that have older versions of Android can still use my application.

The app in mind ATM is fairly simple, I just want to be able to understand how to implement the layout and then I’ll add the missing bits.

Anyhow, I have a Container Activity that extends Fragment Activity (to ensure compatibility), and this Activity creates a TabView using an ActionBar (I believe my problem resides here). The app will try to create three tabs and add them to the ActionBar, and I want to make sure the user can scroll back and forth using lateral navigation.

Here is TabListener I am trying to implement:

public static class TabListener<T extends Fragment> implements ActionBar.TabListener {

    private Fragment mFragment;
    private final Activity mActivity;
    private final String mTag;
    private final Class<T> mClass;

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

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        if (mFragment == null) {
            mFragment = Fragment.instantiate(mActivity, mClass.getName());
            ft.add(android.R.id.content, mFragment, mTag);
        } else {
            ft.attach(mFragment);
        }
    }

    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        if (mFragment != null) {
            ft.detach(mFragment);
        }
    }

    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }
}

Here are my imports, because I wanted to make sure I was using the support library:

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.Menu;

However, Eclipse is giving me issues with the TabListener methods. It is telling me the following: “The type LayoutContainer.TabListener must implement the inherited abstract method ActionBar.TabListener.onTabSelected(ActionBar.Tab, FragmentTransaction)”

When I select Add unimplemented methods Eclipse basically adds the OnTabSelected OnTabReselected and OnTabUnselected methods, but this time, passing the non-support version of the Fragment (android..app.Fragment) as a parameter.

Any ideas on how to make another implementation of lateral navigation through the support library to ensure compatibility?

  • 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-12T07:01:17+00:00Added an answer on June 12, 2026 at 7:01 am
    actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    
    tabA = actionBar.newTab().setText("");
    tabB = actionBar.newTab().setText("");
    
    Fragment fragmentA = new AFragmentTab();
    Fragment fragmentB = new BFragmentTab();
    
    tabA.setTabListener(new MyTabsListener(fragmentA));
    tabB.setTabListener(new MyTabsListener(fragmentB));
    
    actionBar.addTab(tabA);
    actionBar.addTab(tabB);
    

    The tab listener is as follows:

    protected class MyTabsListener implements ActionBar.TabListener{
        private Fragment fragment;
    
        public MyTabsListener(Fragment fragment){
            this.fragment = fragment;
        }
        public void onTabSelected(Tab tab, FragmentTransaction ft){
            ft.add(R.id.layout2, fragment, null);
        }
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            ft.remove(fragment);
        }
    }
    

    and then you make a class for each tab:

    public class BFragmentTab extends Fragment {
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            return inflater.inflate(R.layout.login, container, false);
        }
    }
    

    But keep in mind that the action bar isn’t supported for android versions below 3.0 . If you want to use it in older versions I suggest you use actionBarSherlock Library.

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

Sidebar

Related Questions

I'm trying to implement tab buttons bar and a navigation bar in my android
I'm trying to implement in WPF tab that behaves like the one in IE9.
I've been trying to implement the tab UI described in this tutorial: https://developer.android.com/resources/tutorials/views/hello-tabwidget.html I
I am trying to implement a layout that looks like a tabbed view, but
I am trying to implement a tab-style navigation system in my app (similar to
I am trying to implement this tab style in my program, i have it
I'm trying to implement tabs for navigation in an Android app. Since TabActivity and
I have a page where I am trying to implement a simple two tab
I'm trying to make it so I have a tab bar at the bottom
I am trying to implement signature capture using Rhodes targeting an Android tab. I

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.