Ich versuche eine in AlertDialog
zu implementieren, aber die ist jedes Mal null. Ich rufe auf Knopfdruck die Methode hotelBooking an, die sich in einer Aktivität befindet. Was fehlt mir hier?Android MapView innerhalb von AlertDialog
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();
}
Das ist es, vielen Dank! – Kzaf