0

私はアンドロイドグーグルマップを使用していますマップと名前と閉じるボタンと移動ボタンに異なるピンがあります。ポップアップがマップに表示されていますが、別のピンをクリックすると例外が発生します:-

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;
}

事前にこの目標を達成する方法を教えてください。

4

1 に答える 1

2

BidNearItemizedOverlayに送信しているViewpopUpにはすでに親が含まれているようです。addView(popUp、mapParams)を呼び出すときは、2番目の親を指定しようとしています。これは許可されていません。本当に使用したい場合は、最初に親から切り離す必要があります。最も簡単な解決策は、実際のビューを使用するのではなく、popUpのプロパティに基づいて新しいビューを作成することです。

または試してみてください:

((ViewGroup)popUp.getParent()).removeView(popUp);
于 2012-10-06T17:08:41.400 に答える