I am currently using the predefined navigation type "Tabs + swipe" (initially chosen when I created my project).
I have three tabs and I need two listview and one MapActivity. I succedded in displaying listview thanks to FragmentList but now I am trying to display a MapActivity and my code doesn't work at all :/
Here is what I added:
public static class MyFragment extends Fragment {
int idList;
private MapView map=null;
private MyLocationOverlay me=null;
static MyFragment newInstance(int num) {
MyFragment f = new MyFragment();
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return(new FrameLayout(getActivity()));
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
map = new MapView(getActivity(), "xxxxxxxxxx");
map.setClickable(true);
Drawable marker=getResources().getDrawable(R.drawable.ic_action_search);
marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());
map.getOverlays().add(new ItemizedOverlay(marker, getActivity()));
me = new MyLocationOverlay(getActivity(), map);
map.getOverlays().add(me);
((ViewGroup)getView()).addView(map);
}
}
Into getItem(int) in my FragmentPagerAdapter I do this:
public Fragment getItem(int position) {
if(position == 0)
return MyFragment.newInstance(0);
}
And then I got this error:
10-02 18:28:41.618: E/AndroidRuntime(23677): FATAL EXCEPTION: main
10-02 18:28:41.618: E/AndroidRuntime(23677): java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity.
10-02 18:28:41.618: E/AndroidRuntime(23677): at com.google.android.maps.MapView.<init>(MapView.java:291)
10-02 18:28:41.618: E/AndroidRuntime(23677): at com.google.android.maps.MapView.<init>(MapView.java:235)
Any idea about what should I do?