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

enter image description here

Now I have five fragments (tabs) in the application, as shown in the figure. And they are all listed as members of the tab bar in 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 the search tab, I was wondering if it is possible to create another page (or fragment) that displays the search result, and when I click on the result, I want to make it direct to the corresponding tabs (Profile for users and Github Repos for search repo).

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

+4
source share
1 answer

TabLayout ViewPager .

0

Source: https://habr.com/ru/post/1688661/


All Articles