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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:31:00+00:00 2026-05-26T12:31:00+00:00

How from class BasicActivity call method stackAFragment from subclass Sub ? I want to

  • 0

How from class BasicActivity call method stackAFragment from subclass Sub?

I want to have an opportunity to replace Fragment in my Activity Sub from any Activity that extends BasicActivity by using menu. I am going to create a method in Sub for each item menu. Here is a simple example how I see it:

public class BasicActivity extends FragmentActivity {   
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.m_main, menu);
      return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()){
      case R.id.stad:
        TabHost tabHost = (TabHost) getParent().findViewById(android.R.id.tabhost);
        tabHost.setCurrentTab(4); //here is me Sub.class
        //How to call method stackAFragment here?
      break;
      default:
         return false;      
    }
    return true;
  }
}

Subclass:

    public class Sub extends BasicActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sub);        
    }

    public void stackAFragment() {
        Fragment f = new StadFr();      
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.the_frag, f);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.addToBackStack(null);
        ft.commit();
    }
}
  • 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-26T12:31:01+00:00Added an answer on May 26, 2026 at 12:31 pm

    Create an overridable method in BasicActivity (with an empty implementation for instance) and override it in Sub.

    public class BasicActivity extends FragmentActivity {   
    
        protected void onTabChanged(){ }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()){
              case R.id.stad:
                TabHost tabHost = (TabHost) getParent().findViewById(android.R.id.tabhost);
                tabHost.setCurrentTab(4); //here is me Sub.class
                onTabChanged();
          break;
          default:
             return false;      
        }
        return true;
    }
    
    public class Sub extends BasicActivity {
    
        protected void onTabChanged() { stackAFragment(); }
    
       ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have created two objects from class foo and now want to
I have two classes and want to have a reference from class Kunde to
How to call from class oneThread: back to class fun:? As in, address a
I have to open a page from class extended from javax.swing.AbstractAction class... Is that
Is it possible to call functions from class like this: $class = new class;
Say we have a class inheriting from two base classes (multiple inheritance). Base class
I have a bunch of Objects from the same Class in Python. I've decided
I have written a small class, which reads out annotation from methods. Now I
In the following example, the class Derived implements the abstract method method from class
Class A derive from class B. In class A I want to hide some

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.