显示自定义ListView对话框作为地图标记的infoWindow被点击

时间:2014-01-04 09:04:17

标签: android google-maps listview google-maps-api-2 customdialog

我能够将Map Marker的infoWindow链接到TextView活动。点击infoWindow时,会出现textView活动。所以,我想尝试链接到ListView自定义对话框。到目前为止,我没有取得任何进展,因为每次我尝试点击infoWindow时,程序都会终止。我发现我的代码中没有警告。可能代码仍然缺乏。有人会帮助我吗?我只是在这里自学。

我有来自MainActivity的这个,这是针对infoWindow的点击事件

    map.setOnInfoWindowClickListener(new OnInfoWindowClickListener(){

    @Override
    public void onInfoWindowClick(Marker adminmarker){
    Intent intent = new Intent("com.android.cmumap.ADMIN");
    startActivity(intent);
    }
    });

我有这个用于AdminActivity,这是用于自定义对话

    package com.android.cmumap;

    import android.app.AlertDialog;
    import android.app.Dialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.support.v4.app.DialogFragment;

    public class AdminActivity extends DialogFragment{

    public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
    builder.setTitle(R.string.layers)
           .setItems(R.array.layer_options, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
               // The 'which' argument contains the index position
               // of the selected item
           }
    });
    return builder.create();
    }
    }

我有这个用于adminactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView android:id="@+id/layers"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/layers" />

<ListView android:id="@+id/layer_options"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:divider="#000000"
          android:dividerHeight="1dp"
          android:paddingLeft="1dp" />
</LinearLayout>

请告诉我缺少什么..我不能自己做这件事..

1 个答案:

答案 0 :(得分:0)

在你的代码中,你是exted dialogfragment所以它不是一个活动。你应该扩展活动

public class AdminActivity extends Activity{

        public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(AdminActivity.this);
        builder.setTitle(R.string.layers)
               .setItems(R.array.layer_options, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int which) {
                   // The 'which' argument contains the index position
                   // of the selected item
               }
        });
        return builder.create();
        }
        }

并在您的主要活动中执行此操作

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener(){

    @Override
    public void onInfoWindowClick(Marker adminmarker){
    Intent intent = new Intent(MainActivity.this,AdminActivity.class);
    startActivity(intent);
    }
    });

在您的AdminActivity类中只需覆盖OnCreateMethod并从中调用onCreateDialog函数(因此您的管理活动有两个方法onCreateDialog和onCreate)。

   @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     Dialog dialog=onCreateDialog(savedInstanceState)
        dialog.show();
    }