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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:44:15+00:00 2026-06-07T00:44:15+00:00

Hello! I’ve been programming for a long time but just started developing for android,

  • 0

Hello!

I’ve been programming for a long time but just started developing for android, which seems to be quite different from c++ to say at least…

Anyway, I’m trying to implement a gui with some tabs, that should be able to change tab on swipe left/right. The tabs are implemented with actionbar (or ActionBarSherlock to be precise), the swiping with ViewPager from the support lib. The individual tabs are fragments (SherlockFragment:s that is). At the bottom there should be a statusbar of some kind just displaying some text.

The problem I’m having is that the tabs are never shown. I see the actionbar on top with logo/title, with a tab list under it. At the bottom of the screen I see the statusbar-text, but nothing else.

If I uncomment the line //context.setContentView(pager); in SwipeBar() constructor, the content of the tabs are shown, but then the statusbar is not shown. (This line feels really wrong to have here anyway but I can’t figure out how to get some content in my tabs without it.)

I’ve tried everything I can think of. I’ve read everything I could find about it and tried allot of different examples on how to do each functionality by itself. But combining them… I just can’t get this to work. I’d really appreciate your help!


My main (activity) class:
Main.java

public class Main extends SherlockFragmentActivity {
private SwipeBar    tabs;

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tabs = new SwipeBar(this, R.id.pager);
    tabs.add(One.class, "one", null);
    tabs.add(Two.class, "two", null);
    tabs.add(Three.class, "three", null);
}
}

This is my class that implements actionbar/viewpager/fragments:
SwipeBar.java

public class SwipeBar extends FragmentPagerAdapter implements OnPageChangeListener,
    TabListener {
private final ActionBar                 bar;
private final SherlockFragmentActivity  ctx;
private final ViewPager                 pager;
private final ArrayList<TabInfo>        tabs;

public SwipeBar(final SherlockFragmentActivity context, final int viewPagerId) {
    super(context.getSupportFragmentManager());
    bar = context.getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    pager = new ViewPager(context);
    pager.setId(viewPagerId);
    pager.setAdapter(this);
    pager.setOnPageChangeListener(this);
    ctx = context;
    // context.setContentView(pager);
    tabs = new ArrayList<TabInfo>();
}

public void add(final Class<?> clss, final int tabHeaderStringId, final Bundle args) {
    final ActionBar.Tab tab = bar.newTab();
    final TabInfo info = new TabInfo(clss, args);
    tab.setTag(info);
    tab.setText(tabHeaderStringId);
    tab.setTabListener(this);
    tabs.add(info);
    bar.addTab(tab);
    notifyDataSetChanged();
}

@Override
public int getCount() {
    return tabs.size();
}

@Override
public Fragment getItem(final int pos) {
    final TabInfo info = tabs.get(pos);
    return Fragment.instantiate(ctx, info.clss().getName(), info.args());
}

public void onPageScrolled(final int arg0, final float arg1, final int arg2) {}

public void onPageScrollStateChanged(final int arg0) {}

public void onPageSelected(final int pos) {
    bar.setSelectedNavigationItem(pos);
}

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

public void onTabSelected(final Tab tab, final FragmentTransaction ft) {
    final TabInfo tag = (TabInfo)tab.getTag();
    for(int i = 0; i < tabs.size(); i++)
        if(tabs.get(i) == tag) pager.setCurrentItem(i);
}

public void onTabUnselected(final Tab tab, final FragmentTransaction ft) {}
}

The main layout:
Main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="0px">    
</android.support.v4.view.ViewPager>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#33FF0000"
    android:gravity="center"
    android:layout_weight="0"
    android:text="statusbar">
</TextView> 

</LinearLayout>

And the code for the three pages:
One/Two/Three.xml/java

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center" >
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="this is tab one" />
</LinearLayout>

public class One extends SherlockFragment {
@Override
public View onCreateView(final LayoutInflater inflater,
            final ViewGroup container, final Bundle savedInstanceState) {
    return (LinearLayout)inflater.inflate(R.layout.one, container, false);
}
}
  • 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-07T00:44:16+00:00Added an answer on June 7, 2026 at 12:44 am

    Okay, I finally solved it. The above code came from trying to add ViewPager functionality to the tabs I had done. I started over and implemented a regular ViewPager (like in the various examples out there) and then added an ActionBar. The actual fragment content is now in the ViewPager and the ActionBar tabs is empty, but set through the ViewPager callbacks to indicate the current one.

    I have still no clue what was wrong with the original attempt though…

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

Sidebar

Related Questions

Hello everyone i am developing an quiz based app in android and i have
hello everyone I am newto programming and I am just a little bit confused.
Hello I have a table on which I have denied SELECT privs to a
Hello! I'm not even sure if this is possible, but hopefully it is in
Hello I have been having trouble with this for a while now. I have
hello creating a custom object may be a widely published topic, but my lack
Hello fellow developers... just to make sure, I want to ask this question: How
Hello I'm a newcomerin JavaScript language. I started to see some examples of JavaScript
Hello, Im working on a solution for Android that will record calls (both out
Hello good morning everyone, i have an iphone app which is still in development

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.