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

  • Home
  • SEARCH
  • 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 6778583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:16:59+00:00 2026-05-26T16:16:59+00:00

Hello I am having difficulty changing the visual view of the fragment activity. I

  • 0

Hello I am having difficulty changing the visual view of the fragment activity. I created all the tabs but onClick I do not know how to pass the activity into that white space.

so the structure of this is a simple activity named Main which just sets the content view to a maintabholder.xml document that holds the fragment view which connects to a class named MainNav whose content view contains all the tabs at the bottom.

maintabholder.xml:

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

<include layout="@layout/header" android:layout_alignParentTop="true"           android:id="@+id/headerArea"></include>
<fragment
    class="my.package.name.MainNav"
    android:id="@+id/fragment_tabs"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</LinearLayout>

MainNav.java code snippet:

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
{
    mRoot = inflater.inflate(R.layout.fragment_tabs, null);
    mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost);
    setupTabs();
    return mRoot;
}

and R.layout.fragment_tabs:

<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EFEFEF">

<RelativeLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:background="@drawable/tab_background"
        android:gravity="center_horizontal"
        android:layout_height="wrap_content" >
    </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            
            android:layout_height="wrap_content">

            <FrameLayout
                android:id="@+id/tab_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <FrameLayout
                android:id="@+id/tab_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
             <FrameLayout
                android:id="@+id/tab_3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
              <FrameLayout
                android:id="@+id/tab_4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
               <FrameLayout
                android:id="@+id/tab_5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </FrameLayout>
</RelativeLayout>

and Finally the contents of an Activity that I want to load into the Fragment (upon pressing the tab1 button)

 public class HomeFragment extends Activity {


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

That is to help you get the gist of things, but the problem occurs here in MainNav.java:

  @Override
   public void onTabChanged(String tabId) {
        Log.d(TAG, "onTabChanged(): tabId=" + tabId);
        if (TAB_HOME.equals(tabId)) {
            updateTab(tabId, R.id.tab_1);
            mCurrentTab = 0;
            return;
        }
   }

when a tab is clicked, it is registered in the onTabChanged activity, and the updateTab function is called:

   private void updateTab(String tabId, int placeholder) {
        FragmentManager fm = getFragmentManager();
        if (fm.findFragmentByTag(tabId) == null) {
            //fm.beginTransaction()
             //      .replace(placeholder, /*need fragment object here*/ , tabId)
             //       .commit();
            //
        }
}

the commented out replace method is looking for an (int, fragment, string) and I guess it should then change the white space for me.

but I don’t understand where I get the fragment object from! This phantom object needs to somehow contain my HomeFragment‘s xml layout and allow me to interact with everything else I’ve coded for the HomeFragment activity.

My first hunch is that my HomeFragment activity needs to extend FragmentActivity instead
just activity. But this is where I am hitting a wall.

There is very little documentation on the compatibility pack methods, but the documentation for TabActivity says not to use TabActivity anymore, so here I am. Developing for Android 2.2+

Insight appreciated.

  • 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-05-26T16:16:59+00:00Added an answer on May 26, 2026 at 4:16 pm

    You can’t put Activities into Fragments, it’s jut that simple. You have to convert your Activities that serve the tab-contents into Fragments. It shouldn’t be a problem, given that you don’t use fragments in those Activities.

    So here are 2 rules to follow:

    1. You can’t put Activities into Fragments.
    2. You can’t put Fragments into Fragments.

    I recommend that you keep that bottom fragment on your layout around just to handle the tab-switches in the tab-widget. If a tab switch happens, you report this to the parent Activity, which will load the corresponding Fragment into the are above the tab-fragment. For this to work, you’d have to modify you layout so it has a ViewGroup above the tab-fragment and below the header. You’d dynamically load the fragments with the tab-contents into that ViewGroup.

    Here’s the layout (maintabholder.xml):

    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    
    <include layout="@layout/header" android:layout_alignParentTop="true"           android:id="@+id/headerArea"></include>
    
    <FrameLayout android:id="@+id/TabContent"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"/>
    
    <fragment
        class="my.package.name.MainNav"
        android:id="@+id/fragment_tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    </LinearLayout>
    

    When a tab-switch happens in your bottom fragment, you tell this to the parent Activity:

    ...
    (YourActivity)getActivity().switchToTab(tabId);
    ...
    

    And in the YourActivity:

    ...
    public void switchToTab(int tabId){
        switch(tabId){
        ...
        case 2:
            getSupportFragmentManager().beginTransaction().replace(R.id.TabContent, TabContentFragment2.newInstance(), "someTag").commit().
        break;
        ...
        }
    }
    

    Something like that.

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

Sidebar

Related Questions

hello i am having same issue, i tried your solution but it didnt help
Hello guys Im having a problem in how to clear the previous activity after
Ok. I know this is probably pretty simple, but I am having a difficult
Hello I am having difficulty using the JTwitter functions to authenticate with my twitter
Hello guys i am having big problems in zend framework i dont know how
Warning: Noob here. I know this is a trivial subject but I'm having a
Hello all having some trouble accessing elements from a returned JSON from Twitter. I'm
Hello I'm having the same problem from this post: Ajax.BeginForm not hiding loading element
Hello I am having a hard time making this UI element look the way
Hello I am having a problem with the numbering of figures using Latex, 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.