我有一个将标记放在Google Map View上的异步方法。在下面的代码中,我试图将对象overlayitem传递给onProgressUpdate方法。我收到了itemizedOverlay.addOverlay不需要数组的编译器错误。我很困惑为什么将overlayitem作为数组传递(即overlayitem [])。有人可以帮忙吗?

  class OverlayLoader extends AsyncTask<Void, OverlayItem, Void> {
    List<Overlay> mapOverlays;

    @Override
    protected void onPreExecute() {
        mapOverlays = mapView.getOverlays();
    }

    @Override
    protected Void doInBackground(Void... params) {
        SQLiteDatabase db = mDbHelper.getReadableDatabase();

        Cursor mCursor = db.query(TABLE_NAME, null, null, null, null, null, null);

        startManagingCursor(mCursor);

        OverlayItem overlayitem = null;

        while (mCursor.moveToNext()) {

            Address = mCursor.getString(4);
            Name = mCursor.getString(0);

            String noSpaces = Address.replaceAll(" ", "+");

            JSONObject geocoded = getLocationInfo(noSpaces);
            GeoPoint point = getGeoPoint(geocoded);

            overlayitem = new OverlayItem(point, Name, Address);

            publishProgress(overlayitem);
        }
        return null;
        }

    protected void onProgressUpdate(OverlayItem... overlayitem) {
        List<Overlay> mapOverlays = mapView.getOverlays();
        String x = "@Hello";
        Log.e("Hello",""+x);
        Drawable drawable = maptabview.this.getResources().getDrawable(R.drawable.pushpin);
        CustomizedItemOverlay itemizedOverlay =
            new CustomizedItemOverlay(drawable, maptabview.this);

        itemizedOverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedOverlay);
    }
}

最佳答案

这样可以做到:

itemizedOverlay.addOverlay(overlayitem[0]);


说明:OverlayItem...称为varargs,是所显示类型的数组。

09-04 13:53