将参数传递给onProgressUpdate时出现问题 - 异步方法

时间:2011-09-11 20:16:04

标签: java android multithreading eclipse asynchronous

我有一个异步方法,可以将标记放在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);
    }
}

1 个答案:

答案 0 :(得分:1)

这样做:

itemizedOverlay.addOverlay(overlayitem[0]); 

说明:OverlayItem...被称为varargs,是一个呈现类型的数组。