0

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...

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
PlugInBoy
  • 979
  • 3
  • 13
  • 25

1 Answers1

1

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.

MonkeyDroid
  • 637
  • 7
  • 14
  • Hi, I discover one thing. If you put a Map inside a Fragment in a Slide view tab, when you try to slide between a fragment and a MapFragment, the focus doesn't move it from Map Activity... – PlugInBoy Apr 15 '13 at 10:38
  • I think you should declare the type of gesture you are using. if a side by side swipe or a border one. – MonkeyDroid Apr 18 '13 at 15:58
  • @MonkeyDroid Can you be more specific about your solution for dealing with swiping on a tab with a MapFragment? – Sean Barbeau Jun 28 '13 at 04:12
  • Is quite like the new drawer added to Android sdk. You get a gesture that starts from the border of the screen and that opens the drawer. If you select the centre of the screen it swipes wetween fragments. So let's say you are listening to the starting point of the gesture and filter it. Here you can find an example dealing with gestures you can start from: [link](http://blog.kerul.net/2010/11/using-fling-motion-gesture-in-android.html) – MonkeyDroid Jun 28 '13 at 11:58