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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:31:40+00:00 2026-06-14T23:31:40+00:00

I try to implement an applicationbar with SWIPE tabs in my android project. Lets

  • 0

I try to implement an applicationbar with SWIPE tabs in my android project.
Lets say I’ve two tabs (tab1 and tab2). And I want to display different content on these tabs.
(Actually that’s all what I want to do nothing more).

Tab1 includes a list and Tab2 includes “another” list plus some text.
Is it possible to use two “activities” for the two tabs? (That’s what I’m doing now)

I use a custom adapter to set the lists content.

 final ListView lv = (ListView)findViewById(R.id.tab1_list);
 lv.setAdapter(new CustomListAdapter(this, tab1Items));

But I’m not able to display the tabs content correctly. Either they aren’t display at all, or they are display the same content.

Does anyone have some good ideas for me, or some little code examples, how to use a appbar with tabs and lists in it (that are using adapters)?

I’m very grateful for any help.

  • 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-14T23:31:41+00:00Added an answer on June 14, 2026 at 11:31 pm

    Here is the example what you want “A swipe Tab”:

    <?xml version="1.0" encoding="utf-8"?>
         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
            <TabHost
                android:id="@android:id/tabhost"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                >
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    >
                    <TabWidget
                        android:id="@android:id/tabs"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="0"
                        />
    
                    <FrameLayout
                        android:id="@android:id/tabcontent"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_weight="0"/>
    
                    <android.support.v4.view.ViewPager
                        android:id="@+id/viewpager"
                        android:layout_width="fill_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"
                        />
                </LinearLayout>
            </TabHost>
        </LinearLayout>
    

    Define the PagerAdapter :

    package com.andy.fragments.viewpager;
    
    import java.util.List;
    
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    
    
    public class PagerAdapter extends FragmentPagerAdapter {
    
        private List<Fragment> fragments;
    
        public PagerAdapter(FragmentManager fm, List<Fragment> fragments) {
            super(fm);
            this.fragments = fragments;
        }
    
        @Override
        public Fragment getItem(int position) {
            return this.fragments.get(position);
        }
    
    
        @Override
        public int getCount() {
            return this.fragments.size();
        }
    }
    

    Define the Tab FragmentActivity:

    package com.andy.fragments.tabs;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Vector;
    
    import android.content.Context;
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.view.ViewPager;
    import android.view.View;
    import android.widget.TabHost;
    import android.widget.TabHost.TabContentFactory;
    
    import com.andy.R;
    import com.andy.fragments.viewpager.PagerAdapter;
    
    
    public class TabsViewPagerFragmentActivity extends FragmentActivity implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {
    
        private TabHost mTabHost;
        private ViewPager mViewPager;
        private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, TabsViewPagerFragmentActivity.TabInfo>();
        private PagerAdapter mPagerAdapter;
    
        private class TabInfo {
             private String tag;
             private Class<?> clss;
             private Bundle args;
             private Fragment fragment;
             TabInfo(String tag, Class<?> clazz, Bundle args) {
                 this.tag = tag;
                 this.clss = clazz;
                 this.args = args;
             }
    
        }
    
        class TabFactory implements TabContentFactory {
    
            private final Context mContext;
    
            public TabFactory(Context context) {
                mContext = context;
            }
    
    
            public View createTabContent(String tag) {
                View v = new View(mContext);
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }
    
        }
    
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.tabs_viewpager_layout);
    
            this.initialiseTabHost(savedInstanceState);
            if (savedInstanceState != null) {
                mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); 
            }
    
            this.intialiseViewPager();
        }
    
    
        protected void onSaveInstanceState(Bundle outState) {
            outState.putString("tab", mTabHost.getCurrentTabTag()); 
            super.onSaveInstanceState(outState);
        }
    
    
        private void intialiseViewPager() {
    
            List<Fragment> fragments = new Vector<Fragment>();
            fragments.add(Fragment.instantiate(this, Tab1Fragment.class.getName()));
            fragments.add(Fragment.instantiate(this, Tab2Fragment.class.getName()));
            fragments.add(Fragment.instantiate(this, Tab3Fragment.class.getName()));
            this.mPagerAdapter  = new PagerAdapter(super.getSupportFragmentManager(), fragments);
    
            this.mViewPager = (ViewPager)super.findViewById(R.id.viewpager);
            this.mViewPager.setAdapter(this.mPagerAdapter);
            this.mViewPager.setOnPageChangeListener(this);
        }
    
    
        private void initialiseTabHost(Bundle args) {
            mTabHost = (TabHost)findViewById(android.R.id.tabhost);
            mTabHost.setup();
            TabInfo tabInfo = null;
            TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Tab 1"), ( tabInfo = new TabInfo("Tab1", Tab1Fragment.class, args)));
            this.mapTabInfo.put(tabInfo.tag, tabInfo);
            TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Tab 2"), ( tabInfo = new TabInfo("Tab2", Tab2Fragment.class, args)));
            this.mapTabInfo.put(tabInfo.tag, tabInfo);
            TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("Tab 3"), ( tabInfo = new TabInfo("Tab3", Tab3Fragment.class, args)));
            this.mapTabInfo.put(tabInfo.tag, tabInfo);
    
            mTabHost.setOnTabChangedListener(this);
        }
    
    
        private static void AddTab(TabsViewPagerFragmentActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
    
            tabSpec.setContent(activity.new TabFactory(activity));
            tabHost.addTab(tabSpec);
        }
    
    
        public void onTabChanged(String tag) {
    
            int pos = this.mTabHost.getCurrentTab();
            this.mViewPager.setCurrentItem(pos);
        }
    
    
        @Override
        public void onPageScrolled(int position, float positionOffset,
                int positionOffsetPixels) {
    
    
        }
    
    
        @Override
        public void onPageSelected(int position) {
    
            this.mTabHost.setCurrentTab(position);
        }
    
    
        @Override
        public void onPageScrollStateChanged(int state) {
    
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to implement a browser-like app. I want to let it can open
I try to implement a non-recursive make build system in my current project. What
When I try to implement Facebook Connect in my Android application, I get the
When I try to implement Facebook Connect in my Android application, I get the
I try to implement GCM in my project and have problems with onMessage function.
I try to implement new validationrules in my MVC-Project but i wont become a
I try to implement the following code, this page will display when survey is
I try to implement checked button in android-uitableview But i cannot handle the click
I'm try to implement caption display in html5, something like: video_element.addEventListener('CUE=11ms',show_sub1,false) how can I
I try to implement animation of the set of different controls with different height

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.