How can I start and Activity from a class extending ItemizedOverlay?
I have a class that extends ItemizedOverlay.
In it, I have:
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
/*// working below code, just replace */
AlertDialog.Builder dialog = new
AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.setPositiveButton("Details",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterfac开发者_如何学编程e dialog, int id) {
}
});
When I click the "Details" button, I want to start an Activity or setContentView, but those methods do not exist.
Any ideas?
Thanks
You have to create an intent.
Intent i = new Intent(this /*context*/, ExampleActivityClass.class /*Your new Activity Class*/);
i.setAction("android.intent.action.VIEW");
startActivity(i);
and you should add an intent-filter to your android manifest:
<activity android:name=".ExampleActivityClass">
<intent-filter>
<action android:name="android.intent.action.VIEW />
</intent-filter>
</activity>
For further information see and read this
Esentian
I'm new to Android but I think you should create Intent to start a new activity (and pass it to Context.startActivity()) .
I defined the class that extended ItemizedOverlay as a private class of the Map Activity, as it was quite specify functionality that wanted to keep with Activity. So methods getApplicationContext() and startActivity() are available.
protected boolean onTap(int index) {
selectedItem = mOverlays.get(index);
Intent i= new Intent(getApplicationContext(), MyNewActivity.class);
i.putExtra(Application.ITEM_KEY, selectedItem));
startActivity(i);
return true;
}
精彩评论