
Listing 7. The onListItemClick() overridden method
@Override
protected void onListItemClick(ListView list,View view,int position,long
dbidentifier)
{
super.onListItemClick(list,view,position,dbidentifier);
try
{
// this commented out code below will launch the Contacts application
// and "view" the contact Intent myIntent = \
new Intent(android.content.
// Intent.VIEW_ACTION,new ContentURI("content://contacts/people/"
// + dbidentifier)); startSubActivity(myIntent,position);
// let's lookup specifics on this record
ContentURI theContact = \
new ContentURI(android.provider.Contacts.ContactMethods.CONTENT_URI.toURI());
// IMPORTANT
// in order to use this sample application, you need to have at least
// one Contact record on your Android emulator\
// and be sure to have populated the 'Home Address field'
//
// this "where clause" is for HOME address and for the person record
// selected in the GUI (id, dbidentifier)
Cursor c = managedQuery(theContact,null," type = 1 and person = " +
dbidentifier,null);
if (!c.first())
{
showAlert("MSCC","No Contact Methods Available!","",true);
return;
}
String address = c.getString(c.getColumnIndex("data"));
address = address.replace("\n","");
address = address.replace(",","");
address = address.replace(" ","+");
Intent geoIntent = new Intent("android.intent.action.VIEW",
new ContentURI\
("geo:0,0?q=" + address));
startActivity(geoIntent);
}
catch (Exception ee)
{
Log.i(tag,ee.getMessage());
}
}
Once the address has been obtained, a few simple string operations are required to
clean up the data to prepare it for a query to Google Maps. The geoIntent is a
new Intent created to perform a geo search, which in the default Android Emulator
image is satisfied by a call to Google Maps.
All of the major elements of the first application still hold true for this application.
ibm.com/developerWorks developerWorks®
Develop Android applications with Eclipse
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 31 of 35
Kommentare zu diesen Handbüchern