2011-01-02 29 views
1

ItemizedOverlayをstartActivityに拡張するクラスを取得しようとしていますが、問題があり、コンパイルできません。 私は、オーバーレイを描画するためにItemizedOverlayクラスを使用するMapViewを持っていますが、私は画面上でタップしたときに開始し、アクティビティを行いたいと思います。ItemizedOverlayクラスからのアクティビティの開始

どのようにこの問題を解決するためのアイデアですか?おかげ

protected boolean onTap(int index) { 
    OverlayItem item = overlays.get(index); 

    String split_items = item.getSnippet(); 
    Intent intent = new Intent(); 
    intent.setClass(mainmenu,poiview.class); 
    startActivity(intent); 


    return true; 
    } 

答えて

-1

Intent intent = new Intent(mainmenu.this, poview.class); 
startActivity(intent); 
+0

=( – Cid

+0

)ItemizedOverlayクラスはアクティビティではありません。コンテキストを使用してその機能を追加できます。 – CQM

5

次使用しようと、私は以下の例をテストしてきたので、私はこの問題を抱えていました。 このソリューションは、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; 
} 
0

、このいずれかを試してみてください、私は...警告ダイアログで正ボタンを設定してそれを行っている

protected boolean onTap(int index) { 
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); 
dialog.setTitle(item.getTitle()); 
dialog.setIcon(R.drawable.info_icon); 
dialog.setPositiveButton("Details", new DialogInterface.OnClickListener() { 
public void onClick(DialogInterface dialog, int which) { 
    Intent placeDetailsMapIntent = new Intent(mContext, PlaceDetailsActivity.class); 
    mContext.startActivity(placeDetailsMapIntent); 
     } 

});

関連する問題