Android 谷歌地图中的ItemizedOverlay问题
我一直试图在点击谷歌地图的标记时弹出一个自定义对话框。我使用此代码重写ItemizeOverlay Cals的onTap()方法Android 谷歌地图中的ItemizedOverlay问题,android,google-maps,dialog,Android,Google Maps,Dialog,我一直试图在点击谷歌地图的标记时弹出一个自定义对话框。我使用此代码重写ItemizeOverlay Cals的onTap()方法 protected boolean onTap(int index) { AlertDialog.Builder builder; AlertDialog alertDialog; Context mContext = getApplicationContext(); L
protected boolean onTap(int index) {
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView textName = (TextView) layout.findViewById(R.id.text);
textName.setText("Here is the Name");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();
return super.onTap(index);
}
下面是自定义对话框布局xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
这正是上给出的示例
需要帮忙吗
谢谢 使用classname.this而不是getApplicationContext 如果它是一个简单的映射活动 如果它位于选项卡中,则使用getParent() 因为badtokenexception在其未采用正确的类引用时发生。更改
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
到
谢谢纽茨:)这正是问题所在。
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = (LayoutInflater) MyActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE);