Issue
I am trying to implement a MapView
in AlertDialog
but the MapView
is null every time. I call, on button click, the method hotelBooking which is inside an Activity. What am i missing here?
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();
}
Solution
MapView mMapView = (MapView) promptView.findViewById(R.id.mapView2);
Try promtView.findViewById
instead of alertDialog.findViewById
Answered By - blackkara
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.