onClick()
のメソッドでdialog.setPositiveButton()
住所、緯度、経度の変数にアクセスできない理由を誰か教えてもらえますonTouchEvent
か?
class MapOverlayClass extends ItemizedOverlay<OverlayItem>
{
private ArrayList<OverlayItem> overlayList = new ArrayList<OverlayItem>();
Context context;
public MapOverlayClass(Drawable drawable)
{
super(boundCenterBottom(drawable));
}
public MapOverlayClass(Drawable defaultMarker,Context context)
{
super(boundCenterBottom(defaultMarker));
this.context=context;
}
//called after we add the overlays to the overlay ArrayList and call populate()
@Override
protected OverlayItem createItem(int i)
{
return overlayList.get(i);
}
@Override
public int size()
{
return overlayList.size();
}
public void addOverlay(OverlayItem overlay)
{
overlayList.add(overlay);
populate();
}
@Override
protected boolean onTap(int i)
{
OverlayItem overlay = overlayList.get(i);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(overlay.getTitle());
builder.setMessage(overlay.getSnippet());
builder.show();
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapview)
{
if(event.getAction()==1)
{
GeoPoint geopoint = mapview.getProjection().fromPixels((int)event.getX(), (int)event.getY());
Geocoder geocoder = new Geocoder(context,Locale.ENGLISH);
Double latitude=null,longitude=null;
latitude = geopoint.getLatitudeE6()/1E6;
longitude = geopoint.getLongitudeE6()/1E6;
String address = "";
try
{
List<Address> list = geocoder.getFromLocation(latitude, longitude, 1);
String featurename = list.get(0).getFeatureName();
String countryname = list.get(0).getCountryName();
String adminarea = list.get(0).getAdminArea();
String premises = list.get(0).getPremises();
if(featurename!=null)
{
address = address+" "+featurename;
}
if(adminarea!=null)
{
address = address+" "+adminarea;
}
if(premises!=null)
{
address = address+" "+premises;
}
if(countryname!=null)
{
address = address+" "+countryname;
}
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle("Location Alarm");
dialog.setMessage("Do you want to set alarm at this location "+address+"?");
dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
Intent intent = new Intent(context,Fill_Information.class);
intent.putExtra("address", address); //HERE
intent.putExtra("address", longitude); //HERE
intent.putExtra("address", latitude); //HERE
context.startActivity(intent);
}
});
dialog.setNegativeButton("No", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
dialog.show();
}
catch (Exception e)
{
Toast.makeText(context, "Address not found.", Toast.LENGTH_LONG).show();
}
}
return false;
}
}