@SuppressWarnings("deprecation")
void showAlertDialog(final LatLng markerPosition) {
AlertDialog alertDialog = new AlertDialog.Builder(GoogleMapViewer.this)
.create();
alertDialog.setTitle("Location Selected");
alertDialog.setMessage("Add this Location to your");
alertDialog.setButton2("Places", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
"You clicked on Places", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setButton3("Activities",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent act_intent = new Intent();
act_intent.setClass(GoogleMapViewer.this,
addActivities.class);
act_intent.putExtra("username", savedUserName);
act_intent
.putExtra("latitude", markerPosition.latitude);
act_intent.putExtra("longitude",
markerPosition.longitude);
startActivity(act_intent);
}
});
alertDialog.show();
}
AlertDialog not showing when i click on marker
-
09-07-2023 - |
質問
*I have created alert dialog to show after clicking on marker
*but when i click on marker it crashes the application.
*What could be the problem? Is there anything am i missing?
Thanks in Advance
googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onMarkerClick(Marker marker) {
showAlertDialog();
return false;
}
});
private void showAlertDialog() {
AlertDialog alert = new AlertDialog.Builder(
getBaseContext()).create();
alert.setTitle("Location Selected");
alert.setMessage("Add this Location to your");
alert.setButton("Places",
new DialogInterface.OnClickListener() {
//code goes here
});
alert.setButton("Activities",
new DialogInterface.OnClickListener() {
//code goes here
}
});
alert.show();
}
解決
他のヒント
Try
AlertDialog.Builder alert = new AlertDialog.Builder(getBaseContext()).create();
instead of
AlertDialog alert = new AlertDialog.Builder(getBaseContext()).create();
所属していません StackOverflow