eclipse - findFragmentById for SupportMapFragment returns null in Android Studio -


Recently I have setup everything migrate a project to Android Studio to Eclipse, which is but one piece It is working and one is working, which uses a SupportMapFragment. SupportMapFragment m = ((SupportMapFragment) getActivity; findFragmentById down (which worked when building Eclipse) now null :(

  return public void OnActivityCreated (bundled savedInstanceState) {super.onActivityCreated (savedInstanceState) the () .getSupportFragmentManager () findFragmentById (R.id.safety_map));  

xml piece ...

  & lt; FrameLayout xmlns: . Android = "http://schemas.android.com/apk/res/android" xmlns: Map = "http://schemas.android.com/apk/res-auto" Android: layout_width = "match_parent" Android: Layout_height = "match_parent" Android: orientation = "vertical" & gt; & lt; piece Android: id Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: layout_marginBottom = "40dp" map: cameraTargetLat = "@ string / lifef_latitudes" map: cameratab: target = "@ string / livesf_lange "Maps: uiZoomControls =" false "class =" com.google.android.gms.maps.SupportMapFragment "/>  

My dependencies are based on my build. Gradl:

  dependencies {// google analytics compilation 'com.google.apis: google-api-services -analytics: v3-rev103-1.19.0' api 'support library for 10 Compilation 'Com.android.support:support-v4:21.0.0' // Google Play services collection 'com.google.android.gms: play Services: 6.1.11' compile project (': Facebook') compile files ('libs / android- support multidex.jar ') compile files (' libs / Adblyues- Android-SDK-1.6.0-debug.jar ') compile files (' libs / flurryanalytics_3.3.2.jar ')}  

I have not changed any code in XML file or fragment class Who had previously worked in Iklips.

Based on the fact that you are overriding Fragment.onActivityCreated () , I take it that in your layout the map slice is the layout for your piece , in that case, SupportMapFragment a children < / Em> is the piece of your hosting piece . When you try to retrieve it, you are using activity fragment manager . You should instead use your fragment of fragment manager :

, for example:

  SupportMapFragment M = (SupportMapFragment) getActivity () .getSupportFragmentManager (). FindFragmentById (R.id.safety_map));  

becomes:

  SupportMapFragment meter = (get supportMapFragment) getChildFragmentManager () .findFragmentById (R.id.safety_map));  

Comments