2011-09-11 47 views
0

我有一個異步方法,它將標記放在Google Map視圖中。在下面的代碼中,我試圖將對象overlayitem傳遞給onProgressUpdate方法。我得到一個編譯器錯誤,itemizedOverlay.addOverlay不期望數組。我很困惑爲什麼overlayitem被作爲數組傳遞(即overlayitem [])。誰能幫忙?將參數傳遞給onProgressUpdate的問題 - 異步方法

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

這就能做到:

itemizedOverlay.addOverlay(overlayitem[0]); 

說明:OverlayItem...稱爲varargs並且呈現類型的陣列。

+0

謝謝。最後 ! – GuybrushThreepwood