我正在使用 android 谷歌地图,地图上有不同的引脚,名称和关闭按钮以及移动按钮。弹出窗口显示在地图上,但是当单击另一个引脚时会出现异常:-
10-06 22:17:17.080: E/AndroidRuntime(25156): FATAL EXCEPTION: main
10-06 22:17:17.080: E/AndroidRuntime(25156): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.addViewInner(ViewGroup.java:3011)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.addView(ViewGroup.java:2900)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.addView(ViewGroup.java:2880)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.appstudioz.bidnear.map.BidNearItemizedOverlay.onTap(BidNearItemizedOverlay.java:85)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.View.dispatchTouchEvent(View.java:4609)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1554)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1320)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1732)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1267)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.app.Activity.dispatchTouchEvent(Activity.java:2315)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1705)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1732)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1267)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.app.Activity.dispatchTouchEvent(Activity.java:2315)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1705)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.View.dispatchPointerEvent(View.java:4677)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2394)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.view.ViewRoot.handleMessage(ViewRoot.java:2054)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.os.Looper.loop(Looper.java:132)
10-06 22:17:17.080: E/AndroidRuntime(25156): at android.app.ActivityThread.main(ActivityThread.java:4123)
10-06 22:17:17.080: E/AndroidRuntime(25156): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 22:17:17.080: E/AndroidRuntime(25156): at java.lang.reflect.Method.invoke(Method.java:491)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
10-06 22:17:17.080: E/AndroidRuntime(25156): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
10-06 22:17:17.080: E/AndroidRuntime(25156): at dalvik.system.NativeStart.main(Native Method)
我将此代码用作:-我的网络服务提供了具有纬度,经度并在地图上显示为的对象数量:-
MapController objmapcontroller;
GeoPoint objgeopointp;
double lat, lng;
try {
lat = Double.parseDouble(latitude);
lng = Double.parseDouble(longitude);
} catch (Exception e) {
e.printStackTrace();
lat = lng = 0;
}
objgeopointp = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
objmapcontroller = objmapView.getController();
// ---Add a location marker---
// create and add an OverlayItem to the MyItemizedOverlay list
OverlayItem overlayitem = new OverlayItem(objgeopointp, title, snippet);
itemizedoverlay.addOverlay(overlayitem);
objmapcontroller.animateTo(objgeopointp);
objmapcontroller.setZoom(16);
// add the overlays to the map
mapOverlays.add(itemizedoverlay);
objmapView.invalidate();
而我的覆盖类就像那个类 Ontap 方法一样,整个类就像
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
private MapView objmapview;
private View popUp;
public BidNearItemizedOverlay(Drawable defaultMarker, Context ctx,MapView objmapview,View popUp) {
super(boundCenterBottom(defaultMarker));
mContext =ctx;
this.objmapview=objmapview;
this.popUp=popUp;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
public void clear() {
mOverlays.clear();
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
Log.e("------size--",""+mOverlays.size());
return mOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item=getItem(index);
GeoPoint geo=item.getPoint();
MapView.LayoutParams mapParams = new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
geo,
MapView.LayoutParams.BOTTOM_CENTER);
TextView objtxt = (TextView)popUp.findViewById(R.id.textup);
TextView objtxt2 = (TextView)popUp.findViewById(R.id.text2);
objtxt.setText(item.getTitle());
objtxt2.setText(item.getSnippet());
ImageView objimg = (ImageView)popUp.findViewById(R.id.bluebutton);
ImageButton objbtn = (ImageButton)popUp.findViewById(R.id.closebutton);
objbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("aclosehjdfd");
}
});
objimg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("hohodshfsdh");
}
});
objmapview.addView(popUp, mapParams);
return true;
}
请任何人建议我如何实现这个目标提前谢谢..