Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy cant I access these variables in my anonymous inner class?
    primarykey
    data
    text
    <p>Can anyone tell me why I can't access address, latitude and longitude variables in the <code>onClick()</code> method of <code>dialog.setPositiveButton()</code> of <code>onTouchEvent</code>?</p> <pre><code>class MapOverlayClass extends ItemizedOverlay&lt;OverlayItem&gt; { private ArrayList&lt;OverlayItem&gt; overlayList = new ArrayList&lt;OverlayItem&gt;(); 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&lt;Address&gt; 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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload