Here is some of my java code:public class Mapscreen extends Activity {
public MapView map;
public boolean m_isMapLoaded;
//Callout Variables
private int m_calloutStyle;
private Callout m_callout;
private ViewGroup calloutContent;
private Graphic m_identifiedGraphic;
ArcGISFeatureLayer fLayer;
ImageView CallOutClose;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
// Initial activity content view. (START)
super.onCreate(savedInstanceState);
setContentView(R.layout.mapscreen);
// Retrieve the map layout and initial extent from mapscreen XML layout.
map = (MapView) findViewById(R.id.map);
// Add ESRI basemap layer to MapView.
map.addLayer(new ArcGISTiledMapServiceLayer("" +
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"));
// Add Feature layer to the MapView
String URL = "ADD YOUR MAP SERIVCE HERE";
ArcGISFeatureLayer fLayer = new ArcGISFeatureLayer(URL, MODE.ONDEMAND);
map.addLayer(fLayer);
// This puts the ERSI logo on the bottom left corner of the screen once the map screen appears. This is mandatory
// by ESRI.
map.setEsriLogoVisible(true);
LayoutInflater inflater = getLayoutInflater();
// Get the MapView's callout from xml->identify_calloutstyle.xml
m_calloutStyle = R.xml.facility_calloutstyle;
// Get the layout for the Callout from layout->identify_callout_content.xml
calloutContent = (ViewGroup) inflater.inflate(R.layout.facility_callout_content, null);
m_callout = map.getCallout();
m_callout.setContent(calloutContent);
// This initiates/starts the loading dialog when entering into map screen.
final ProgressDialog loadingDialog = new ProgressDialog(this);
loadingDialog.setMessage("Loading...");
loadingDialog.show();
// This initiates the listening process to see if the map loads.
map.setOnStatusChangedListener(new OnStatusChangedListener() {
private static final long serialVersionUID = 1L;
@Override
public void onStatusChanged(Object source, STATUS status) {
// Check to see if map has successfully loaded or Initialized.
if ((source == map) && (status == STATUS.INITIALIZED)) {
// If the map is loaded successfully set the flag to true and hide the loading dialog.
m_isMapLoaded = true;
loadingDialog.hide();
}
// Check to see if the map has unsuccessfully loaded or Initialization failed.
// Initialization failed typically results from no wireless connectivity.
if (OnStatusChangedListener.STATUS.INITIALIZATION_FAILED == status) {
// If the map did not load set the flag as false and hide the loading dialog.
m_isMapLoaded = false;
loadingDialog.hide();
// Because the map failed to load, the following toast will appear briefly with the following message.
Toast toast = Toast.makeText(Mapscreen.this,"Failed to load...Connection
Issue",Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
});
//Callout Part - 1
map.setOnSingleTapListener(new OnSingleTapListener() {
private static final long serialVersionUID = 1L;
@Override
public void onSingleTap(float x, float y) {
if (m_isMapLoaded) {
// If map is initialized and Single tap is registered on screen identify the location selected
identifyLocation(x, y);
}
}
});
}
// Initial activity content view. (END)
//Callout Part - 2
/**
* Takes in the screen location of the point to identify the feature on map.
*
* @param x
* x co-ordinate of point
* @param y
* y co-ordinate of point
*/
private void identifyLocation(float x, float y) {
// Hide the callout, if the callout from previous tap is still showing on map
if (m_callout.isShowing()) {
m_callout.hide();
}
// Find out if the user tapped on a feature
SearchForFeature(x, y);
// If the user tapped on a feature, then display information regarding the feature in the callout
if (m_identifiedGraphic != null) {
Point mapPoint = map.toMapPoint(x, y);
// Show Callout
ShowCallout(m_callout, m_identifiedGraphic, mapPoint);
//Close button for the callout is initiated here.
ImageView CallOutClose = (ImageView) findViewById(R.id.callout_close_button);
CallOutClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
m_callout.hide();
}
});
}
}
//Callout Part - 3
/**
* Sets the value of m_identifiedGraphic to the Graphic present on the
* location of screen tap
*
* @param x
* x co-ordinate of point
* @param y
* y co-ordinate of point
*/
private void SearchForFeature(float x, float y) {
Point mapPoint = map.toMapPoint(x, y);
if (mapPoint != null) {
for (Layer layer : map.getLayers()) {
if (layer == null)
continue;
if (layer instanceof ArcGISFeatureLayer) {
ArcGISFeatureLayer fLayer = (ArcGISFeatureLayer) layer;
// Get the Graphic at location x,y
m_identifiedGraphic = GetFeature(fLayer, x, y);
} else
continue;
}
}
}
//Callout Part - 4
/**
* Returns the Graphic present the location of screen tap
*
* @param fLayer
* @param x
* x co-ordinate of point
* @param y
* y co-ordinate of point
* @return Graphic at location x,y
*/
private Graphic GetFeature(ArcGISFeatureLayer fLayer, float x, float y) {
// Get the graphics near the Point.
int[] ids = fLayer.getGraphicIDs(x, y, 10, 1);
if (ids == null || ids.length == 0) {
return null;
}
Graphic g = fLayer.getGraphic(ids[0]);
return g;
}
//Callout Part - 5
/**
* Shows the Attribute values for the Graphic in the Callout
*
* @param calloutView
* @param graphic
* @param mapPoint
*/
private void ShowCallout(Callout calloutView, Graphic graphic, Point mapPoint) {
// Get the values of attributes for the Graphic
String Name = (String) graphic.getAttributeValue("Name");
String Phone = (String) graphic.getAttributeValue("Phone");
String LatDegMinSec = (String) graphic.getAttributeValue("LatDegMinSec");
String LongDegMinSec = (String) graphic.getAttributeValue("LongDegMinSec");
String Website = (String) graphic.getAttributeValue("Website");
// Set callout properties
calloutView.setCoordinates(mapPoint);
calloutView.setStyle(m_calloutStyle);
calloutView.setMaxWidth(700);
calloutView.setMaxHeight(500);
// Compose the string to display the results
StringBuilder FacilityCallout = new StringBuilder();
FacilityCallout.append("Facility:\t" + Name);
FacilityCallout.append("\nPhone:\t" + Phone);
FacilityCallout.append("\nLatitude:\t" + LatDegMinSec);
FacilityCallout.append("\nLongitude:\t" + LongDegMinSec);
FacilityCallout.append("\nWebsite:\t" + Website);
TextView calloutTextLine1 = (TextView) findViewById(R.id.callout_content_textview);
calloutTextLine1.setText(FacilityCallout);
calloutView.show();
}