我正在尝试在
AlertDialog
中实现一个MapView
,但每次MapView
都是空的。我在按钮单击时调用了一个Activity中的hotelBooking方法。我错过了什么吗?public void hotelBooking(final String hotelname){
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Hotel Info");
alertDialog.setIcon(R.drawable.action_hotels);
LayoutInflater layoutInflater = LayoutInflater.from(context);
View promptView = layoutInflater.inflate(R.layout.traveler_hotel_registration, null);
alertDialog.setView(promptView);
MapView mMapView = (MapView) alertDialog.findViewById(R.id.mapView2);
MapsInitializer.initialize(this);
mMapView.onCreate(alertDialog.onSaveInstanceState());
mMapView.onResume();
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(final GoogleMap googleMap) {
LatLng posisiabsen = new LatLng(40.626401, 22.948352); ////your lat lng
googleMap.addMarker(new MarkerOptions().position(posisiabsen).title(hotelname));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(posisiabsen));
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
}
});
final RatingBar rb = (RatingBar) promptView.findViewById(R.id.ratingBar);
rb.setRating(3);
final TextView hoteltitle= (TextView)promptView.findViewById(R.id.HotelInfoTitle);
hoteltitle.setText("Hotel " + hotelname);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Favorite", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText(getApplicationContext(), "Hotel has been saved to favorites!",
Toast.LENGTH_LONG).show();
}
});
alertDialog.show();
}