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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:12:05+00:00 2026-06-03T07:12:05+00:00

I am trying to avoid using intents and activities within tabhost and tabwidget This

  • 0

I am trying to avoid using intents and activities within tabhost and tabwidget

This code is starting to get messy just using views for everything.

My problem is that I am having difficulty retaining information. In one tab I have one view which has 4 buttons, each button loads another view and this takes up the visual information on screen in that tab. The problem is that when I go “back” to load the previous view in that tab, none of the information is that view is retained, even the button listeners won’t re-instantiate.

How do I approach this? I have seen some very rudimentary examples of views within tabs, but nothing interactive that loads more views.

(viewflippers and action bars are not an option, and I am trying to avoid using tabs with activities)

  • 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-03T07:12:07+00:00Added an answer on June 3, 2026 at 7:12 am

    Forget Activity Group. Forget Tab Host. It’s all about ActionBar Tabs and ViewPager Fragments now. The API Demos sample app (which is also the Android Compatibility Library sample app) provides an implementation that combines both Tab and ViewPager navigation between Fragments, but it sort of fakes the Tabs (i.e., they are not true ActionBar tabs). See FragmentTabsPager.java. You can take this and make it work with true ActionBar tabs, too.

    Here’s the interesting bit. (I deleted a bunch of stuff, so don’t look for a complete working solution here.)

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.fragment_tabs_pager);
    
        mViewPager = (ViewPager)findViewById(R.id.pager);
    
        // This block thanks to https://stackoverflow.com/q/9790279/517561
        ActionBar bar = getSupportActionBar();
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        bar.setDisplayShowTitleEnabled(true);
        bar.setDisplayShowHomeEnabled(true);
        //
    
        mTabsAdapter = new TabsAdapter(this, mViewPager);
    
        mTabsAdapter.addTab("simple", "Simple", 
                FragmentStackSupport.CountingFragment.class, null);
        mTabsAdapter.addTab("contacts", "Contacts",
            LoaderCursorSupport.CursorLoaderListFragment.class, null);
        mTabsAdapter.addTab("custom", "Custom",
            LoaderCustomSupport.AppListFragment.class, null);
        mTabsAdapter.addTab("throttle", "Throttle",
            LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
    }
    
    public static class TabsAdapter extends FragmentPagerAdapter
            implements ViewPager.OnPageChangeListener, ActionBar.TabListener {
        private final SherlockFragmentActivity mContext;
        private final ViewPager mViewPager;
        private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
    
        static final class TabInfo {
            @SuppressWarnings("unused")
            private final String tag;
            private final Class<?> clss;
            private final Bundle args;
    
            TabInfo(String _tag, Class<?> _class, Bundle _args) {
                tag = _tag;
                clss = _class;
                args = _args;
            }
        }
    
        static class DummyTabFactory implements TabHost.TabContentFactory {
            private final Context mContext;
    
            public DummyTabFactory(Context context) {
                mContext = context;
            }
    
            @Override
            public View createTabContent(String tag) {
                View v = new View(mContext);
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }
        }
    
        public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) {
            super(activity.getSupportFragmentManager());
            mContext = activity;
            mViewPager = pager;
            mViewPager.setAdapter(this);
            mViewPager.setOnPageChangeListener(this);
        }
    
        public void addTab(String tag, CharSequence label, Class<?> clss, Bundle args) {
            ActionBar.Tab tab = mContext.getSupportActionBar().newTab();
            tab.setText(label);
            tab.setTabListener(this);
            mContext.getSupportActionBar().addTab(tab);
            TabInfo info = new TabInfo(tag, clss, args);
            mTabs.add(info);
            notifyDataSetChanged();    
        }
    
        @Override
        public Fragment getItem(int position) {
            TabInfo info = mTabs.get(position);
            return Fragment.instantiate(mContext, info.clss.getName(), info.args);
        }
    
        @Override
        public void onPageSelected(int position) {
            mContext.getSupportActionBar().setSelectedNavigationItem(position);
        }
    
        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
          mViewPager.setCurrentItem(mContext.getSupportActionBar().getSelectedNavigationIndex());
        }
    }
    

    My complete solution: http://code.google.com/p/sherlock-demo/

    Note: Requires ActionBarSherlock.
    Note: Thanks to ActionBarSherlock and FragmentTabsPager

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

Sidebar

Related Questions

I've been trying to avoid using a cursor in this particular case just because
I'm trying to avoid code like this when reusing the same ViewUserControl in ASP.NET
From the get go, let me say that I'm trying to avoid using pcntl_fork()
This is a follow-up to this question . I'm trying to avoid using an
I'm trying to avoid using Interface Builder as much as possible. At the moment
I am trying to avoid using Net::SSH::Perl library since there is some problems in
I'm trying to avoid a composite control or using and ASCX by extending an
After trying to avoid JavaScript for years, Iv started using Query for validation in
I'm trying to avoid handling this improperly encoded request on the server. I have
I'm trying to avoid using a long else if statement. Lets say I have

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.