0

I try to display a MapView in the TabPageIndicator of the ViewPageIndicator Library. To use the MapView in a Fragment, im working with the android-support-v4-r10.googlemaps.jar.

So far i can display the MapView, but it wont react on Touch-Events. I cant zoom or pan...

My MapFragment:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    root = (View) inflater.inflate(R.layout.training_map, container, false);
    mapViewContainer = (ViewGroup) root.findViewById(R.id.map_container);
    return root;
}

@Override
public void onActivityCreated(Bundle bundle) {
    super.onActivityCreated(bundle);
    LoggingHelper.i("", "onActivityCreated");

    initTextViews();
    mapView = ((TrainingActivity) getActivity()).getMapView();
    //Zeigt einen blauen Punkt am derzeitigen Standort an
    locationOverlay = new MyLocationOverlay(getActivity(), mapView);
    locationOverlay.runOnFirstFix(new Runnable() {
        @Override
        public void run() {
            if(mapController != null){
                mapController.animateTo(locationOverlay.getMyLocation());
            }
        }
    });
    locationOverlay.enableMyLocation();
    mapViewContainer.addView(mapView);

}

The xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tracking_maps_main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:visibility="visible" >
    <LinearLayout
        android:id="@+id/map_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    </LinearLayout>

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:onClick="onClickLock"
        android:src="@android:drawable/ic_lock_lock" />

</RelativeLayout>

FragmentActivity:

                ...
        //Paging Initialisieren
    adapter = new TrainingFragmentAdapter(getSupportFragmentManager(), fragments);
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(adapter);
    pageIndicator = (TabPageIndicator) findViewById(R.id.indicator);
    pageIndicator.setViewPager(viewPager);
            ...

    public MapView getMapView(){
    if(mapView == null){
        mapView = new MapView(this, "my-googlemaps-key...");
    }
    return mapView;
}
iTamp
  • 793
  • 1
  • 8
  • 12

1 Answers1

0

I believe the default value for MapView.setClickable() is false.

Try the following:

if(mapView == null){
    mapView = new MapView(this, "my-googlemaps-key...");
    mapView.setClickable(true); //add this line
}

Regards.

Luis
  • 11,978
  • 3
  • 27
  • 35