タイトルとスニペット以外の値を OverlayItem に渡したいと思います。いくつかの検索を行ったところ、OverlayItem のサブクラスを作成することが解決策になることがわかりました。しかし、私はそれを書く方法がわかりません。
VenueMapActivity.class
public void drawVenue(){
........
Drawable marker = getResources().getDrawable(R.drawable.mall2);
VenueMapOverlay venuePos = new VenueMapOverlay(marker,mapView);
String getAdd;
StringBuilder strReturnedAddress = new StringBuilder("Address: ");
try {
// Getting Array data from php
venues = json.getJSONArray(TAG_VENUE);
GeoPoint[] mallCoords = new GeoPoint[venues.length()];
// looping through All data
for(int i = 0; i < venues.length(); i++){
....
mallCoords[i] = new GeoPoint((int)(lat * 1E6),(int)(lng *1E6));
List<Overlay> overlays = mapView.getOverlays();
// The custom of overlayItem
OverlayItem overlayItem = new CustomItem(mallCoords[i], name, strReturnedAddress.toString(), vid);
venuePos.addOverlay(overlayItem);
venuePos.setCurrentLocation(currentLocation);
overlays.add(venuePos);
}
}
catch(JSONException e){
e.printStackTrace();
}
}
//To allow intent when balloon is clicked
public void startCustomActivity(Context context, String tmp){
Intent Details = new Intent(context, InfoActivity.class);
Details.putExtra("Id", tmp);
context.startActivity(Details);
}
class CustomItem extends OverlayItem {
String venueid =null;
CustomItem(GeoPoint pt, String name, String snippet,
String venueid) {
super(pt, name, snippet);
this.venueid = venueid ;
}
VenueMapOverlay.class
public class VenueMapOverlay extends BalloonItemizedOverlay<OverlayItem> {
private Context mContext;
private ArrayList<OverlayItem> venues = new ArrayList<OverlayItem>();
private Location currentLocation;
public VenueMapOverlay(Drawable defaultMarker, MapView mapView) {
super(boundCenter(defaultMarker), mapView);
mContext = mapView.getContext();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return venues.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return venues.size();
}
public void addOverlay(OverlayItem overlay) {
venues.add(overlay);
populate();
}
public void setCurrentLocation(Location loc){
this.currentLocation = loc;
}
public Location convertGpToLoc(GeoPoint gp){
Location convertedLocation = new Location("");
convertedLocation.setLatitude(gp.getLatitudeE6() / 1e6);
convertedLocation.setLongitude(gp.getLongitudeE6() / 1e6);
return convertedLocation;
}
@Override
protected boolean onBalloonTap(int index, OverlayItem item) {
String tmp = venues.get(index).getTitle();
VenueMapActivity sub = new VenueMapActivity();
sub.startCustomActivity(mContext, tmp);
return true;
}
}
OnBalloonTap メソッドで、venueid の値を取得するにはどうすればよいですか??
私を助けてください。ありがとうございました。