Android google map can't be found -
Android google map can't be found -
i have layout shows map on app
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/fragment_create_instant_album_create_button_text_view" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerinparent="true" android:orientation="vertical" android:paddingleft="30dp" android:paddingright="30dp" > <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="left" android:text="@string/instant_album_info" android:textcolor="@color/pico_clay" /> <edittext android:id="@+id/fragment_create_instant_album_album_name_text_view" android:layout_width="match_parent" android:layout_height="40dp" android:layout_margintop="15dp" android:background="@drawable/blue_border_edittext_unselected" android:hint="@string/album_name" android:paddingleft="15dp" android:textcolor="@color/pico_dark_grey" android:textcolorhint="@color/pico_grey_blue" android:textsize="@dimen/text_medium" /> <fragment android:id="@+id/fragment_create_instant_album_map_fragment" android:layout_width="match_parent" android:layout_height="150dp" android:layout_margintop="15dp" class="com.google.android.gms.maps.supportmapfragment" android:background="@drawable/blue_border_edittext_unselected" android:paddingbottom="8dp" android:paddingtop="8dp" android:tag="map" /> <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margintop="15dp" android:gravity="center_vertical" android:paddingtop="8dp" > <radiogroup android:id="@+id/fragment_create_instant_album_privacy_radio_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > </radiogroup> </linearlayout> </linearlayout> </relativelayout> <com.coapps.pico.fonts.robototextview android:id="@+id/fragment_create_instant_album_create_button_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:background="@color/pico_salmon" android:gravity="center" android:paddingbottom="20dp" android:paddingtop="20dp" android:text="@string/create_instant_album" android:textappearance="@android:style/textappearance.large" android:textcolor="@android:color/white" /> </relativelayout>
but when using code map fragment, homecoming null (although i'm seeing map)
albumname = (textview) view .findviewbyid(r.id.fragment_create_instant_album_album_name_text_view); createalbum = (textview) view .findviewbyid(r.id.fragment_create_instant_album_create_button_text_view); mapfragment = (supportmapfragment) mainactivity.getsupportfragmentmanager().findfragmentbytag("map");
why? doing wrong?
try map
googlemap mmap = ((supportmapfragment) getactivity() .getsupportfragmentmanager().findfragmentbyid(r.id.fragment_create_instant_album_map_fragment)) .getmap();
if still gives null, seek alternate.first of all, replace map fragment in xml framelayout
<framelayout android:id="@+id/fl_map" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" />
and in onactivitycreated of fragment, create supportmapfragment this
supportmapfragment fragment= (supportmapfragment) getchildfragmentmanager().findfragmentbyid(r.id.ll_map); if (fragment == null) { fragment = supportmapfragment.newinstance(); fm.begintransaction().replace(r.id.fl_map, fragment).commit(); } googlemap mmap=fragment.getmap();
and in ondetach() of fragment, set code
@override public void ondetach() { super.ondetach(); seek { field childfragmentmanager = fragment.class .getdeclaredfield("mchildfragmentmanager"); childfragmentmanager.setaccessible(true); childfragmentmanager.set(this, null); } grab (nosuchfieldexception e) { throw new runtimeexception(e); } grab (illegalaccessexception e) { throw new runtimeexception(e); } }
android google-maps
Comments
Post a Comment