次使用しようと、私は以下の例をテストしてきたので、私はこの問題を抱えていました。 このソリューションは、MapActivityコンテキストから "startActivity"を呼び出すことに依存しています。
Mapがオーバーレイで実際に動作している場合、MapView ContextをカスタムItemizedOverlayコンストラクタに渡している可能性があります。また、MapView ContextをmContextというクラス変数に割り当てました(GoogleのMapViewの例)。
@Override
protected boolean onTap(int index) {
Intent intent = new Intent(mContext, ActivityYouAreTryingToLaunch.class);
mContext.startActivity(intent);
return true;
}
をしかし、あなたはおそらく、あなたがそうあなたの新しい活動はあなたの選択に有用な何かを行うことができます起動しようとしている新しい活動に何かを渡したい:だからあなたのカスタムオーバーレイのONTAP機能で、これを行います。だから... ...
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
//assumption: you decided to store an "id" in the snippet so you can associate this map location with your new Activity
long id = Long.parseLong(item.getSnippet()); //Snippet is a built-in String property of an Overlay object.
//pass an "id" to the class so you can query
Intent intent = new Intent(mContext, ActivityYouAreTryingToLaunch.class);
String action = Intent.ACTION_PICK; //You can substitute with any action that is relevant to the class you are calling
//I create a URI this way because I append the id to the end of the URI (lookup the NotePad example for help because there are many ways to build a URI)
Uri uri = ContentUris.withAppendedId(Your_CONTENT_URI, id);
//set the action and data for this Intent
intent.setAction(action);
intent.setData(uri);
//call the class
mContext.startActivity(intent);
return true;
}
=( – Cid
)ItemizedOverlayクラスはアクティビティではありません。コンテキストを使用してその機能を追加できます。 – CQM