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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:08:52+00:00 2026-06-07T12:08:52+00:00

how to make the method onWindowFocusChanged(boolean) to true(or call) in one tabs of tablayout

  • 0

how to make the method onWindowFocusChanged(boolean) to true(or call) in one tabs of tablayout in android..

Explanation:

In tablayout onWindowFocusChanged() called automatically in default activity (true), But when we click/touch on to the next tab ( which call another activity)
not able to call the onWindowFocusChanged() !!!!!! how to call onWindowFocusChanged() in second tab?

source code:

public class TabTestActivity extends TabActivity {

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);



            Resources res = getResources();

            TabHost tabHost = getTabHost();  

            TabHost.TabSpec spec;  

            Intent intent;  



            // Create an Intent to launch an Activity for the tab (to be reused)

            intent = new Intent().setClass(this, TabOne.class);



            // Initialize a TabSpec for each tab and add it to the TabHost

            spec = tabHost.newTabSpec("TabOne").setIndicator("TabOne",

                              res.getDrawable(R.drawable.ic_tab_One))

                          .setContent(intent);

            tabHost.addTab(spec);



            // Do the same for the other tabs

            intent = new Intent().setClass(this, TabTwo.class);

            spec = tabHost.newTabSpec("TabTwo").setIndicator("TabTwo",

                              res.getDrawable(R.drawable.ic_tab_az))

                          .setContent(intent);

            tabHost.addTab(spec);
            //tabHost.setCurrentTab(2);

        }


                  public void onWindowFocusChanged(boolean hasFocus) {

                    // TODO Auto-generated method stub

                     Toast.makeText(this, ""+hasFocus , Toast.LENGTH_LONG).show();

                       super.onWindowFocusChanged(hasFocus);

                    }
  }
 -----------------------------------------------------------------------------------------------------   

    public class TabOne extends Activity {

         public void onCreate(Bundle savedInstanceState) {

                super.onCreate(savedInstanceState);

                TextView textview = new TextView(this);

                textview.setText("This is the Coll tab");

                setContentView(textview);

            }

        @Override

        public void onWindowFocusChanged(boolean hasFocus) {

            // TODO Auto-generated method stub



            Toast.makeText(this, "On window One"+hasFocus , Toast.LENGTH_LONG).show();

            super.onWindowFocusChanged(hasFocus);

        }

    }

--------------------------------------------------------------------------    

    public class TabTwo extends Activity {

         public void onCreate(Bundle savedInstanceState) {

                super.onCreate(savedInstanceState);



                TextView textview = new TextView(this);

                textview.setText("This is the Coll tab");

                setContentView(textview);

            }



        @Override

        public void onWindowFocusChanged(boolean hasFocus) {

            // TODO Auto-generated method stub

            Toast.makeText(this, "On window TabTwo"+hasFocus , Toast.LENGTH_LONG).show();

            super.onWindowFocusChanged(hasFocus);


        }

  }

TabTwo’s (2ndTab) onWindowFocusChanged not called while TabTwo activity runs please give the solution.
I tried to provide tabHost.setFocusable(true); I doesn’t worked!!!

  • 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-07T12:08:54+00:00Added an answer on June 7, 2026 at 12:08 pm

    Tabs are basically deprecated. You should use fragments instead. This will clearly handle your issue.

    See: https://stackoverflow.com/questions/9714650/converting-tabactivity-into-fragmentactivity for an example of how to do this.

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

Sidebar

Related Questions

I'd like to make a method called isBetween returning a boolean, seeing if a
How to make this method return boolean value, depending on query return. False -
I have tried to make method which changes one color of BufferedImage to be
How does one make a method in an interface that's not abstract? I know
could any one help me make a method that will delete data from the
In C#, one can make a method such as this: [Conditional(DEBUG)] private void MyFunction()
I need to give an automatically constructed method positional and default parameters. If I
I'm able to make the method for the call [self weaponAttachments:mpk5] but I don't
I am trying to make a method for a class that will automatically insert
Is there any simple way to make a method that gets called whenever the

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.