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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:10:04+00:00 2026-05-27T05:10:04+00:00

I have an android program with 3 tabs. When I click on the Map

  • 0

I have an android program with 3 tabs. When I click on the “Map Tab” I want it to display “Map is Selected” message as shown in the picture bellow. But if I click on “Name” tab and then come back to the “Map Tab” the second time, the “Map is Selected Again” message wouldn’t show up in the screen. How can I make the “Map” tab display “Map is Selected Again” message each time I choose that tab? Can you edit the following code and show with an example about how to use OnTabChangeListener?

public class MapsActivity extends MapActivity implements OnTabChangeListener {    

@Override
public void onCreate(Bundle savedInstanceState)
{ 
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main4);
    Toast.makeText(getApplicationContext(),"Map is Selected", Toast.LENGTH_LONG).show();        
}

public void onTabChanged(String tabId) {
    Toast.makeText(getApplicationContext(),"Map Selected Again", Toast.LENGTH_LONG).show(); 
}

@Override
protected boolean isRouteDisplayed() {
    return false;
} }

enter image description here

Updated. but the following method doesn’t output a message.

`public class HelloTabWidget extends TabActivity implements OnTabChangeListener{`

    private TabHost mTabHost;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); 
        TabHost tabHost = getTabHost();  
        TabHost.TabSpec spec;  
        Intent intent; 

        intent = new Intent().setClass(this, BarActivity.class);
        spec = tabHost.newTabSpec("Name").setIndicator("Name",res.getDrawable(R.drawable.ic_tab_name)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, CityActivity.class);
        spec = tabHost.newTabSpec("city").setIndicator("City",res.getDrawable(R.drawable.ic_tab_city)).setContent(intent); 
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, MapsActivity.class);
        spec = tabHost.newTabSpec("Map").setIndicator("Map",res.getDrawable(R.drawable.ic_tab_map)).setContent(intent);
        tabHost.addTab(spec);        

        tabHost.setCurrentTab(2);
    }

    public void onTabChanged(String tabId) {
        mTabHost = getTabHost();
        mTabHost.setOnTabChangedListener(this);
        Toast.makeText(getApplicationContext(), "To check for Display", Toast.LENGTH_LONG).show();
        Log.i("selected tab index", "Current index - "+ mTabHost.getCurrentTab());      
    }} 
  • 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-27T05:10:05+00:00Added an answer on May 27, 2026 at 5:10 am

    You should implement OnTabChangeListener to the TabActivity class rather than the contents of the Tab.

    In your TabActivity implement OnTabChangeListener

    then set the listener for the TabHost mTabHost.setOnTabChangedListener(this);

    @Override
        public void onTabChanged(String tabId) {
            Log.i("selected tab ", tabId);
    
        }
    

    UPDATE

    public class HelloTabWidget extends TabActivity implements OnTabChangeListener{`
    
        private TabHost mTabHost;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Resources res = getResources(); 
            TabHost tabHost = getTabHost();  
            TabHost.TabSpec spec;  
            Intent intent; 
            mTabHost = getTabHost();
    
    
            intent = new Intent().setClass(this, BarActivity.class);
            spec = tabHost.newTabSpec("Name").setIndicator("Name",res.getDrawable(R.drawable.ic_tab_name)).setContent(intent);
            tabHost.addTab(spec);
    
            intent = new Intent().setClass(this, CityActivity.class);
            spec = tabHost.newTabSpec("city").setIndicator("City",res.getDrawable(R.drawable.ic_tab_city)).setContent(intent); 
            tabHost.addTab(spec);
    
            intent = new Intent().setClass(this, MapsActivity.class);
            spec = tabHost.newTabSpec("Map").setIndicator("Map",res.getDrawable(R.drawable.ic_tab_map)).setContent(intent);
            tabHost.addTab(spec);        
    
            tabHost.setCurrentTab(2);
            mTabHost.setOnTabChangedListener(this);
        }
    
        public void onTabChanged(String tabId) {
            Toast.makeText(getApplicationContext(), "Selected Tab "+tabId, Toast.LENGTH_LONG).show();
            Log.i("selected tab index", "Current index - "+ mTabHost.getCurrentTab());      
        }} 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done one program in android using xml parsing but there is an
I want to access/add/read etc google calender from my Android program. I have tried
I have a Android program which you type in equation and them program display
I want to create rounded buttons in an Android program. I have looked at
I have an Android app I made and everything works but I want to
I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how
I want install Android version 1.6 SDK. I already have Android development setup with
We have an Android app and a Web Service. We want to download part
I have a Android project for SDK1.5 and now I want to convert it
I have an android activity in which I'm using tabs. public class UnitActivity extends

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.