2011-08-15 3 views
3

내 안드로이드 앱에지도가 있습니다. 기본적으로 위성보기가 표시되지만 도로지도보기 만 표시하도록 설정했습니다. 그러나 사용자가 메뉴 버튼을 눌렀을 때 '토글 위성지도'와 함께 하단에 섹션이 표시되도록 메뉴를 구성하는 방법이 궁금합니다. 그냥 활동이 추가이지도 유형을 변경하기위한 Android지도 메뉴 만들기

답변

0

도움이 될 수 있습니다 사람에게

덕분에 (내가 미래에 메뉴에 다른 항목을 추가 할 예정) :

@Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.menu_items, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case R.id.item1 : 
     //do what you like 
     default : 
     return super.onOptionsItemSelected(item); 
    } 
    } 

이 별도의에 있어야 (어쩌면 /res/menu/menu_items.xml) XML 파일

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:id="@+id/item1" 
      android:icon="@android:drawable/ic_menu_help" 
      android:title="Help" /> 
    <item android:id="@+id/item2" 
      android:icon="@android:drawable/ic_menu_manage" 
      android:title="Settings" /> 
</menu> 
0

메뉴/버튼/탭/당신의-선택과 이벤트 리스너에 구축이 수행이 기능은 위성을 도로지도로 변환합니다. 건배.

18

이것은 GoogleMaps API v2에서 잘 작동하는 구현입니다. 지도 유형을 선택할 수있는 네 개의 라디오 버튼이있는 대화 상자를 보여줍니다. 현재 선택된지도 유형도 이미 선택되어 있습니다.

Android AlertDialog to select GoogleMaps MapType

이 코드는 바람직하게지도를 보유하고 활동에 간다. showMapTypeSelectorDialog()를 호출하기 전에지도가 시작되고 올바르게 표시되는지 확인하십시오. 또한 레이블에 리소스 문자열을 사용하는 것이 좋습니다.

private GoogleMap mMap; 

... 

private static final CharSequence[] MAP_TYPE_ITEMS = 
     {"Road Map", "Hybrid", "Satellite", "Terrain"}; 

private void showMapTypeSelectorDialog() { 
    // Prepare the dialog by setting up a Builder. 
    final String fDialogTitle = "Select Map Type"; 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setTitle(fDialogTitle); 

    // Find the current map type to pre-check the item representing the current state. 
    int checkItem = mMap.getMapType() - 1; 

    // Add an OnClickListener to the dialog, so that the selection will be handled. 
    builder.setSingleChoiceItems(
      MAP_TYPE_ITEMS, 
      checkItem, 
      new DialogInterface.OnClickListener() { 

       public void onClick(DialogInterface dialog, int item) { 
        // Locally create a finalised object. 

        // Perform an action depending on which item was selected. 
        switch (item) { 
         case 1: 
          mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
          break; 
         case 2: 
          mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); 
          break; 
         case 3: 
          mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
          break; 
         default: 
          mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
        } 
        dialog.dismiss(); 
       } 
      } 
    ); 

    // Build the dialog and show it. 
    AlertDialog fMapTypeDialog = builder.create(); 
    fMapTypeDialog.setCanceledOnTouchOutside(true); 
    fMapTypeDialog.show(); 
} 
+1

감사합니다. @easytarget 당신은 방금 내 주말을 저장했습니다. :) –