Skip to content Skip to sidebar Skip to footer

Findfragmentbyid Always Returns A Null

I'm using an actionbar in navigation mode in the mainActivity. Different tabs has different layouts, and on one of these tabs, I embed a layout which has a MapFragment inside. Wit

Solution 1:

This happens because the MapFragment has not finished loading the google map object. To fix this try overriding onActivityCreated when you create the map fragment. From your implementation of onActivityCreated then do all of your map accesses and modifications.

myMapFragment=newSupportMapFragment(){
    @OverridepublicvoidonActivityCreated(Bundle savedInstanceState){
        //modify your map here
    }
}

Solution 2:

In mi case the problem was not specify SupportMapFragment. I have uses like this:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"class="com.google.android.gms.maps.SupportMapFragment" />

As explained here https://stackoverflow.com/a/16663713/2411379 for Google Map V2 use.

Post a Comment for "Findfragmentbyid Always Returns A Null"