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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:22:55+00:00 2026-05-29T07:22:55+00:00

I would like to use one Activity which holds several fragments and navigate among

  • 0

I would like to use one Activity which holds several fragments and navigate among the fragments. For example, in the activity, there is a list view which is a fragment, when user select one item from the list, the view will navigate to another fragment, How could this be implemented?

I know there is a nice tutorial on the developer site, but it handles the tablet screen in which two pane layout with one list fragment and one detailed fragment showing in one screen. I only want to navigate among fragments without show two fragments in one screen.

Are there tutorials can teach me how to do it?

  • 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-29T07:22:56+00:00Added an answer on May 29, 2026 at 7:22 am

    In the nutshell the answer to your question is to notify your host activity and then have your host activity replace your current fragment container using FragmentManager.

    One of the approach is to make an interface in your first fragment, have your host activity register/listen (implement) to this interface and then have your FragmentManager to replace the container content with the second fragment on listener callback.

    I’m not sure about tutorial but here is my snippet:
    First Fragment

    public class First extends Fragment{
    private static onMySignalListener listener;
    
    //call this function from whatever you like i.e button onClickListener
    public void switchWindow() {
        if(listener != null){
            listener.onMySignal();
        }
    }
    
    public interface onMySignalListener {
        //customize this to your liking
    
        //plain without argument
        void onMySignal();
    
        //with argument
        void onMySignalWithNum(int mNum);
    }
    
    public static void setOnMySignalListener(onMySignalListener listener) {
        First.listener = listener;
    }}
    

    Host Activity

    public class HostActivity extends FragmentActivity implements onMySignalListener{
    private final String ADD_TAG_IF_NECESSARY = "mTag";
    
    @Override
    public void onCreate(Bundle ssi) {
        setContentLayout(R.layout.main);
    
        FirstFragment.setOnMySignalListener(this);
    }
    
    @Override
    public void onMySignal() {
        //if you're using compat library
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
    
        //initialize your second fragment
        sfragment = SecondFragment.newInstance(null);
        //replace your current container being most of the time as FrameLayout
        transaction.replace(R.id.container, fragment, ADD_TAG_IF_NECESSARY);
        transaction.commit();
    }
    
    @Override
    public void onMySignalWithNum(int mNum) {
        //you can do the same like the above probably with your own customization
    }}
    

    This is only an example on how you’d implement interface, kindly tidy it up by yourself. And please be noted though that this is not effective if you have a lot of fragment wanting to notify your host activity about something. doing so will lead you to implement various listener to your host activity.

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

Sidebar

Related Questions

I would like to use Akka to implement a multiple-readers / one-writer pattern on
I would like to use Google Chrome instead of the WebKit Framework in one
I would like to use Date() function in hibernate criteria, since one field is
I would like to create one EMF object and use it in various Resource
I would like to write a rather simple content application which displays a list
I have an array of Integers in Java, I would like use only a
I would like to use R to extract the speaker out of scripts formatted
I would like to use Maven's password encryption such as it uses for nodes
I would like to use the logout function from Django but not sure how
I would like to use D3.js (or maybe Raphaël ) for backend-generated reports using

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.