0
我使用谷歌Android地圖上有地圖和Nam和關閉按鈕和移動button.popup是顯示在地圖上,但不同的引腳,當點擊其他引腳給予例外: -爲什麼彈出不起作用?
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)
我用這代碼: - 我的web服務給具有經緯度對象,長的數,顯示在地圖上爲: -
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;
}
請任何人建議我如何實現這個目標,在此先感謝..