开发者

Android : Hello, Views > Google Map View Tuorial

开发者 https://www.devze.com 2022-12-29 07:49 出处:网络
I\'m trying to complete the Android MapView tutorial @ www.developer.android.com/resources/tutorials/views/hello-mapview.html

I'm trying to complete the Android MapView tutorial @ www.developer.android.com/resources/tutorials/views/hello-mapview.html

I think I've done the entire thing correctly but I'm getting an error message in Eclipse. I'm sure why. The problematic line of code is

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

I'm relatively new to Java but I've gone through the forums of different things and I really have no idea on this one. I've [attached][2] a screen shot of the development environment - hopefully it wont be anything too obvious or hard to fix either!

http://www.limedomains.com/files/download/34780?dirname=&file_name=hellogooglemaps.jpg

Cheers

Tom :)

** As requested heres the source code and the screenshot link is updated to something that works**

package com.example.hellogooglemaps;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

public class HelloItemizedOverlay extends ItemizedOverlay{

    public HelloItemizedOverlay(Drawable defaultMarker) {
          super(boundCenterBottom(defaultMarker));
        }

    @Override
    protected OverlayItem createItem(int i) {
      return mOverlays.get(i);
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    public int size() {
      return mOverlays.size();
    }

    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
          super(defaultMarker);
          mContext = context;
        }

    @Override
    protected boolean onTap开发者_Go百科(int index) {
      OverlayItem item = mOverlays.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.show();
      return true;
    }
}


You need to declare the ArrayList inside the class, not outside, like this:

public class HelloItemizedOverlay extends ItemizedOverlay {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
}


Your screenshot is impossible to read.. please copy/paste what the logcat says...

For my personnal use, i use this code: List mapOverlays;

0

精彩评论

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