Android - 删除标记前显示确认对话框

时间:2013-03-28 17:45:57

标签: android google-maps marker

我正在使用谷歌地图api v2开发一个应用程序,我有一些标记。使用onInfoWindowClick,我删除了标记,但是我想显示一个带有“删除”和“取消”按钮的确认弹出窗口,以便用户可以确认删除。这可能吗?这是我的代码,我的问题是我无法访问“onClick”中的“marker”:

public void onInfoWindowClick(Marker marker) {
LayoutInflater li = LayoutInflater.from(context);
final View v = li.inflate(R.layout.deletelayout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(v);
builder.setCancelable(true);
builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which){
       //I cannot get access to the marker in here
    }});
builder.setNegativeButton("Cancel", null);
AlertDialog alert = builder.create();
alert.show();

//marker.remove();

}

1 个答案:

答案 0 :(得分:4)

更改public void onInfoWindowClick(Marker marker) {

要  public void onInfoWindowClick(final Marker marker) {

您现在应该能够访问onClick

中的标记变量
相关问题