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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:23:28+00:00 2026-06-14T15:23:28+00:00

I have 5 activities in a Tabhost. (i.e MainActivity.java Home.java, NowReading.java, Favorites.java, and Profile.java).

  • 0

I have 5 activities in a Tabhost. (i.e MainActivity.java Home.java, NowReading.java, Favorites.java, and Profile.java). In the main activity I’m loading the tabhost, as show below.

public class MainActivity extends TabActivity {
    TabHost tabHost;
    Context context = MainActivity.this;
    TextView txt_Login;
    View homeTabLayout;
    View reviewLayout;

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

        txt_Login = (TextView) findViewById(R.id.txt_Login);
        final Spinner spnrLanguage = (Spinner) findViewById(R.id.spnrLanguage);
        final Spinner spnrBrowseBy = (Spinner) findViewById(R.id.spnrBrowseBy);

        tabHost = getTabHost();

        // Android tab
        Intent intentHome = new Intent().setClass(this, Home.class);
        TabSpec tabSpecHome = tabHost
                .newTabSpec("Home")
                .setIndicator("Home",
                        getResources().getDrawable(R.drawable.home))
                .setContent(intentHome);

        tabHost.addTab(tabSpecHome);

        Intent intentNowReading = new Intent().setClass(this, NowReading.class);
        TabSpec tabSpecNowReading = tabHost
                .newTabSpec("Now Reading")

                .setIndicator("Now Reading",
                        getResources().getDrawable(R.drawable.now_reading))
                .setContent(intentNowReading);
        tabHost.addTab(tabSpecNowReading);

        Intent intentFavourite = new Intent().setClass(this, Favorites.class);
        TabSpec tabSpecFavourite = tabHost
                .newTabSpec("Favourite")
                .setIndicator("Favorites",
                        getResources().getDrawable(R.drawable.favorites))
                .setContent(intentFavourite);
        tabHost.addTab(tabSpecFavourite);

        Intent intentProfile = new Intent().setClass(this, Profile.class);
        TabSpec tabSpecProfile = tabHost
                .newTabSpec("Profile")
                .setIndicator("Profile",
                        getResources().getDrawable(R.drawable.profile))
                .setContent(intentProfile);
        tabHost.addTab(tabSpecProfile);
tabHost.setCurrentTabByTag("Home");

in the Mainactivity.java im setting The Home.java as current Tab. as

tabHost.setCurrentTabByTag("Home");

which loads the layout home_activity.xml in the setContentView.

enter image description here

here is the XML code

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frameLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/rel_HomeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <GridView
            android:id="@+id/gridview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:numColumns="auto_fit"
            android:stretchMode="columnWidth" >
        </GridView>
    </RelativeLayout>

    <ScrollView
        android:id="@+id/scroll_ReviewLayout"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:id="@+id/rel_ReviewLayout01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/img_OverVuBookCoverPhoto"
                android:layout_width="130dp"
                android:layout_height="165dp"
                android:layout_margin="5dp"
                android:adjustViewBounds="true"
                android:background="@drawable/rounded_image_borders"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:src="@drawable/book1" />

            <TextView
                android:id="@+id/txt_revwBookTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/img_OverVuBookCoverPhoto"
                android:layout_marginTop="10dp"
                android:layout_toRightOf="@+id/img_OverVuBookCoverPhoto"
                android:text="The Basic Doctrine Of Islam"
                android:textColor="@color/White"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/txt_revwAutherName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txt_revwBookTitle"
                android:layout_marginTop="2dp"
                android:layout_toRightOf="@+id/img_OverVuBookCoverPhoto"
                android:text="By: Andrew J Newman"
                android:textColor="@color/SkyBlue"
                android:textSize="11sp" />

            <TextView
                android:id="@+id/txt_PublishDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txt_revwAutherName"
                android:layout_marginTop="2dp"
                android:layout_toRightOf="@+id/img_OverVuBookCoverPhoto"
                android:text="Published: July, 30 2007"
                android:textColor="@color/DarkGray"
                android:textSize="11sp" />

            <RatingBar
                android:id="@+id/ratingbar"
                style="?android:attr/ratingBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txt_PublishDate"
                android:layout_marginBottom="6dp"
                android:layout_marginTop="6dp"
                android:layout_toRightOf="@+id/img_OverVuBookCoverPhoto"
                android:isIndicator="false"
                android:numStars="5"
                android:rating="5"
                android:stepSize="1" />

            <Button
                android:id="@+id/btnOpenBook"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/img_OverVuBookCoverPhoto"
                android:layout_below="@+id/ratingbar"
                android:layout_toRightOf="@+id/img_OverVuBookCoverPhoto"
                android:text="Open Book"
                android:textColor="@color/Black"
                android:textSize="13sp" />

            <ImageButton
                android:id="@+id/btnBack"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/btnOpenBook"
                android:layout_alignTop="@+id/btnOpenBook"
                android:layout_marginLeft="5dp"
                android:layout_toRightOf="@+id/btnOpenBook"
                android:src="@drawable/pic_btn_back"
                android:textColor="@color/Black"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/txt_BookOverview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/img_OverVuBookCoverPhoto"
                android:layout_below="@+id/img_OverVuBookCoverPhoto"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="20dp"
                android:text="Book Overview"
                android:textColor="@color/White"
                android:textSize="13sp" />

            <TextView
                android:id="@+id/txt_BookOverviewDetails"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/img_OverVuBookCoverPhoto"
                android:layout_below="@+id/txt_BookOverview"
                android:lineSpacingExtra="4dp"
                android:lines="10"
                android:text="Lorem ipsum dolor sit amet, there was nothing that I can do she was dead, for this reasean I m gonna loose every thing consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." >
            </TextView>
        </RelativeLayout>
    </ScrollView>

</FrameLayout>

in the onCreate method of Home.java i have made a Framelayout invisible/Gone (which Contains the Overview of book Cliked) as

  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_activity);

        homeTabLayout = findViewById(R.id.rel_HomeLayout);
        reviewLayout = findViewById(R.id.scroll_ReviewLayout);
        reviewLayout.setVisibility(View.GONE);

now when I click any book it make visible the view which i have made invisible/gone previously on the onCreat method as discussed above using the code

gridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
                    long arg3) {
                // TODO Auto-generated method stub

                Toast.makeText(context, BookTitle.get(pos), Toast.LENGTH_SHORT)
                        .show();
                reviewLayout.setVisibility(View.VISIBLE);

enter image description here

Note: that its not the new actvity rather I have just make Visible a view (i.e reviewLayout.setVisibility(View.VISIBLE);) on the click event.

  • I want to make this view Invisible/Gone on the onBackPressed() method.
  • Where should I call this method, either in the MainActivity.java or in the Home.java file?
  • If I’m calling this method in the MainActivity.java its raising a nullPointerException.
  • 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-14T15:23:29+00:00Added an answer on June 14, 2026 at 3:23 pm

    You can Override BackPress method…
    with help of this you can Hide your Layouts or View…

    @Override
    public void onBackPressed() {
         super.onBackPressed();
                   // Invisible or Gone Your Views here....
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have a TabHost activity that are switching activities, so my main looks like
I have an Android application with a main activity that is the tabhost. I'm
I have Main Activity. That has 4 tabs ( TabHost ). I have overridden
i have to activities AnswerQuestion.java and SendAnswerToServer.java , and i want to send data
I have two activities. In first I come to the second activity from first
I have 2 activities. The first activity is an activity that parses JSON data
I have added 4 activities to a tabhost widget. These work fine. The problem
For example, i have 3 activities.. I also use Tab host with separate activity

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.