开发者

Problem passing argument to onProgressUpdate - Async Method

开发者 https://www.devze.com 2023-04-03 22:36 出处:网络
I have an async method which puts markers on a Google Map View. In the code below I am trying to pass the object overlayitem into the method onProgressUpdate. I am getting a compiler error that the it

I have an async method which puts markers on a Google Map View. In the code below I am trying to pass the object overlayitem into the method onProgressUpdate. I am getting a compiler error that the itemizedOverlay.addOverlay is not expecting an array. I am confused why overlayitem is being passed in as an array (i.e overlayitem[]). Can anyone help ?

  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(drawab开发者_C百科le, maptabview.this);   

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


This will do it:

itemizedOverlay.addOverlay(overlayitem[0]); 

Explanation: the OverlayItem... is called varargs and is an array of presented type.

0

精彩评论

暂无评论...
验证码 换一张
取 消