【发布时间】:2018-05-15 03:09:47
【问题描述】:
我想在自定义对话中显示谷歌地图。但我无法从对话类访问 SupportFragmentManager...
这是我的代码....
public class AddressViewDialog extends MaterialDialog.Builder implements OnMapReadyCallback {
private MaterialDialog reviewDialog;
private double latitude = 23.0;
private double longitude = 90.0;
private SupportMapFragment mMapFragment;
private GoogleMap mMap;
public AddressViewDialog(Context context) {
super(context);
this.context = context;
initializeView();
}
public void initializeView() {
reviewDialog = new MaterialDialog.Builder(this.getContext())
.title(R.string.request_to_introduce)
.customView(R.layout.dialog_pending_introducer_review, true)
.show();
View v = reviewDialog.getCustomView();
mMapFragment = (SupportMapFragment) this.getChildFragmentManager()
.findFragmentById(R.id.fragment);
mMapFragment.getView().setVisibility(View.GONE);
if (latitude != 0.0 && longitude != 0.0) {
mMapFragment.getView().setVisibility(View.VISIBLE);
mMapFragment.getMapAsync(this);
} else
mMapFragment.getView().setVisibility(View.GONE);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng currentLoc = new LatLng(latitude, longitude);
mMap.addMarker(new MarkerOptions().position(currentLoc).title("My Location"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLoc, 14.0f));
}
}
这是我的 xml..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_margin="@dimen/activity_horizontal_margin">
<fragment
android:id="@+id/fragment"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="250dp" />
</LinearLayout>
这行显示错误: mMapFragment = (SupportMapFragment) this.getChildFragmentManager() .findFragmentById(R.id.fragment);
我也试过: mMapFragment = (SupportMapFragment) this.getSupportFragmentManager() .findFragmentById(R.id.fragment);
【问题讨论】:
-
使用
DialogFragment,它的对话框布局与fragment-like 实现
标签: android google-maps-android-api-2