PlugInBoy
PlugInBoy

Reputation: 989

Insert Map into a fragment in Swipe-Tab aplication

I'm developing an app with tabs and swipe. In the tabs I load a fragment with text and images but, when I try to put a Map, It returns error. In the FragmentActivity I have this:

  public Fragment getItem(int position) { 
                Fragment newfragment;

      if (position == 0) {

          newfragment = new Fragment1();

      } else if (position == 1) {

          newfragment = new Fragment2();

      } else if (position == 2) {

          newfragment = new Fragment3();
                      } else if (position == 3) {

          newfragment = new MapFragment();

      } else {

          newfragment = new StartFragment();          }

      return newfragment;         }

MapFragment.java extends from Fragment and the Logcat says I need to call an MapActivity, but I don't find in what way I call a MapActivity and fill the fragment with the MapActivity...

Upvotes: 0

Views: 606

Answers (1)

MonkeyDroid
MonkeyDroid

Reputation: 637

Give a try to this way to select fragments:

public Fragment getItem(int page) {
    Fragment fragment = null;
    switch (page) {
    case 0:
      fragment = new Fragment1();
      break;
    case 1:
      fragment = new Fragment2();
      break;
    case 2:
      fragment = new Fragment3();
      break;
    }
    return fragment;
}

remember to use the fragment manager to initialize the adapter class.

Upvotes: 1

Related Questions