Is it possible to have a fragment that is not in the tab bar?

Viewed 430

enter image description here

Right now, I have five fragments (tabs) in my app as the image shows. And they are all listed as members of the tab bar in the MainActivity.java

public class MainActivity extends AppCompatActivity implements InputTab.SendMessage, FollowingTab.SendMessage, FollowerTab.SendMessage, ProfileTab.SendMessage {

    private SectionsPageAdapter pageAdapter;
    ViewPager viewPager;
    public static String currentUser;

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

        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.container, new ProfileTab());

        fragmentTransaction.commit();

        pageAdapter = new SectionsPageAdapter(getSupportFragmentManager());

        // Sets up the ViewPager with the sections adapter

        viewPager = (ViewPager) findViewById(R.id.container);
        setupViewPager(viewPager);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager((viewPager));

    }

    // Adds fragments to SectionsPageAdapter and gives names for the corresponding tab

    private void setupViewPager(ViewPager viewPager) {
        SectionsPageAdapter adapter = new SectionsPageAdapter(getSupportFragmentManager());
        adapter.addFragment(new InputTab(), "Search");
        adapter.addFragment(new ProfileTab(), "Profile");
        adapter.addFragment(new GithubTab(), "Github Repos");
        adapter.addFragment(new FollowerTab(), "Followers");
        adapter.addFragment(new FollowingTab(), "Followings");
        viewPager.setAdapter(adapter);
    }

Since I implemented a search tab, I was wondering if it's possible to create another page(or fragment) that displays the result of the search, and when I click the result, I want to make it direct to the corresponding tabs (Profile for users, and Github Repos for repo search).

In short, how can I create a page that is not part of the tab and still display it when I press the 'search' button?

1 Answers

Implement your TabLayout and ViewPager inside a fragment instead of the activiry and replace that fragment with the results fragment.

Related