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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:37:38+00:00 2026-06-04T22:37:38+00:00

I am trying to make a tabed interface within the same actvity. this is

  • 0

I am trying to make a tabed interface within the same actvity.
this is my main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+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:layout_width="fill_parent"
      android:layout_height="wrap_content"
    />
    <FrameLayout android:id="@android:id/tabcontent"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      <AnalogClock android:id="@+id/tab1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
      />
      <Button android:id="@+id/tab2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="A semi-random button"
      />
    </FrameLayout>
  </LinearLayout>
</TabHost>

dummy.xml:

<?xml version="1.0" encoding="utf-8"?>

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

      <RatingBar
          android:id="@+id/ratingBar1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" />

  </LinearLayout>

and my activity:

public class LActivity extends Activity {


 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);


     TabHost tabs=(TabHost)findViewById(R.id.tabhost);
     tabs.setup();

   tabs.addTab(tabs.newTabSpec("tag1").setIndicator("1").setContent(R.id.tab1));
   tabs.addTab(tabs.newTabSpec("tag2").setIndicator("2").setContent(R.id.tab2));

the above code works, but if you change R.id.tab2 to R.layout.dummy or R.id.ratingBar1, it throws a nullpointerexception.

i intend to display dummy.xml in a tab.

  • 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-04T22:37:40+00:00Added an answer on June 4, 2026 at 10:37 pm

    The reason that R.id.tab2 works and R.layout.dummy doesn’t is that R.id.tab2 is part of the Activity content view as it is defined in the layout set to it with setContentView.

    You can’t use a layout-id where a view-id is expected, and thats why R.layout.dummy doesn’t work. And you can’t expect it to work when using R.id.ratingBar1 as is not part of the Activity content, and how would the activity know where to get that view? Remember you could have several different layouts using an id ratingBar1.

    What you need to do is place your dummy layout within @android:id/tabcontent. You can do this with just an <include> element. Otherwise, you need to inflate the layout yourself and use the resulting View as an argument to setContent.

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

Sidebar

Related Questions

Trying to make this function dynamic instead of static. This was the original code
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
I'm trying to make a tabbed user interface using an asp:Panel and the asp:TreeView.
im trying make one replace in string from a array but this dont work
Trying to make a Grid Like this using java and I'm assuming a 2d
Trying to make a generic PL/SQL procedure to export data in specific XML format,
I'm trying make this code which is from a Dictionary of Arrays (CODE) from
I've been banging my head against a wall trying make this work for a
I have this wireframe I am working from: http://problemio.com/wireframe.pdf I am trying to make

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.