我在我的应用程序中使用片段,我是新手.有一个片段,我想要显示谷歌地图,并希望得到它的对象,为此,我有一个XML片段,我想在片段本身膨胀它.当我试图给地图视图充气时,它会向我显示getSupportFragmentManager()的错误.
如何获取地图对象然后这是主要问题.我的XML是这样的: -
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
class="com.google.android.gms.maps.SupportMapFragment" />
Run Code Online (Sandbox Code Playgroud)
而我想要获取谷歌地图对象的片段是这样的: -
public class FindMyCar extends Fragment {
private TextView mTvFind;
private TextView mTvPark;
private EditText mEtParkHint;
private GoogleMap map;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.findmycar, null);
initViews(view);
Typeface type = Typeface.createFromAsset(getActivity().getResources().getAssets(),"Multicolore.otf");
mTvFind.setTypeface(type);
mTvPark.setTypeface(type);
mEtParkHint.setTypeface(type);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
}
@Override
public void onDestroy() { …Run Code Online (Sandbox Code Playgroud) android google-maps fragment android-fragments google-maps-android-api-2