1

I have built an Android application that uses tabs to navigate. I am using fragments for the majority of the application, however I need to display one activity. How do i display an activity in case 2. Below is the code i have at the moment, i know it returns a fragment but how do i enable the use of both?

public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
            System.out.println("current position = " + position);
            Fragment fragment = null;
            switch(position){

                case 0:
                    return new diaryFragment();
                case 1:
                    return new newEntryFragment();
                case 2:
                    return new Calendarnew();
        }


          return null;

        }
Logic
  • 2,230
  • 2
  • 24
  • 41
uniStudent
  • 55
  • 1
  • 8

2 Answers2

1
private void displayView(int position) {
        // update the main content by replacing fragments
        Fragment fragment = null;
        switch (position) {
        case 0:

            fragment = new diaryFragment();

            break;
        case 1:

            fragment = new newEntryFragment();

        case 2:

            fragment = new Calendarnew();
            break;

        default:
            break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.frame_container, fragment).commit();


        } else {
            // error in creating fragment
            Log.e("MainActivity", "Error in creating fragment");
        }
Ahmad Sanie
  • 3,678
  • 2
  • 21
  • 56
0

Hi I dont actually get what you are up to but try reading this, maybe it could somehow solve your issue. https://stackoverflow.com/a/2958586/4470313

Community
  • 1
  • 1
lombee
  • 33
  • 4