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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:08:45+00:00 2026-06-14T22:08:45+00:00

I have a screen with two tabs and for each tab I’m trying to

  • 0

I have a screen with two tabs and for each tab I’m trying to run different fragment with different layout.

I currently have the following:

  • MainFragmentActivity – activitiy which extends FragmentActivity
  • mainFraggment_screen – XML for MaiFragmentActivity
  • Fragment1 – activity when user clicks on Tab1
  • fragmnet1_screen – XML for that
  • Fragment2 – activity when user clicks on Tab2
  • fragment2_screen – XML for that

Everything is working but the problem is that when application starts there in just an empty screen with tabs Tab1 and Tab2. Fragment of certain activity only appears when user clicks on Tab2 for example. And when he clicks back on Tab1, fragment for Tab1 appears normally.

I would like for that fragment of Tab1 to start immediately when application starts but I don’t know how to accomplish that.

Any ideas? 😀

  • 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-14T22:08:46+00:00Added an answer on June 14, 2026 at 10:08 pm

    The solution is after adding all the tabs, this needs to be done in onCreate():

    TabInfo activeTab = (TabInfo) this.hashMapTab.get("Tab1");
        FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
        activeTab.fragment = Fragment.instantiate(this,activeTab.className.getName(), activeTab.args);
        ft.add(R.id.tab1, activeTab.fragment, activeTab.tag);
        ft.attach(activeTab.fragment);
        lastTab = activeTab;
        ft.commit();
    

    hashMapTab is a hash map of TabInfo of all tabs. TabInfo is a container of all Tab data, like class name and tag of the tab.

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

Sidebar

Related Questions

I have Two Tabs Tab-1 and Tab-2 at bottom of the screen. Send button
I have selected two components in the Customize Layout screen using a hint from
I'm trying to draw two sprites on the same screen. I have defined the
I have two problems I am trying to solve, one is refreshing the tab
I have created an app with multiple tabs, each with its own layout. I
I have an activity that has two tabs and a list view in each.
I have a WPF application with a screen containing a tab control with two
My application has a following requirement. 1) First screen has two tabs. 2) From
I have a tabbar-based iOS app with two tabs. When I tab into the
I have a screen with two RadioButtonField objects. By default, the first RadioButtonField shows

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.