2011-01-02 4 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"를 호출하는 것에 의존합니다.

지도가 실제로 오버레이와 함께 작동하는 경우 이미 MapView Context를 사용자 지정 ItemizedOverlay 생성자에 전달했으며 mContext라는 클래스 변수에 MapView Context를 할당했을 것입니다 (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); 
     } 

});

관련 문제