2017-05-12 2 views
0

MapView에서 발생하는 터치 이벤트를 보류하려고하지만 리스너가 호출되지 않습니다.MapView onTouchListener가 호출되지 않았습니다

MapActivity

public class MapActivity extends AppCompatActivity implements OnMapReadyCallback { 

    private static final String MAPVIEW_BUNDLE_KEY = "MapViewBundleKey"; 

    private MapView mapView; 
    private GoogleMap map; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_map); 

     // *** IMPORTANT *** 
     // MapView requires that the Bundle you pass contain _ONLY_ MapView SDK 
     // objects or sub-Bundles. 
     Bundle mapViewBundle = null; 
     if (savedInstanceState != null) { 
      mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY); 
     } 
     mapView = (MapView) findViewById(R.id.view_map); 
     mapView.onCreate(mapViewBundle); 

     mapView.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View view, MotionEvent event) { 

       Log.d("debug", "Listener"); 
       int action = MotionEventCompat.getActionMasked(event); 

       switch (action) { 

        case (MotionEvent.ACTION_DOWN) : 
         Log.d("debug","Action was DOWN"); 
         break; 
        case (MotionEvent.ACTION_MOVE) : 
         Log.d("debug","Action was MOVE"); 
         break; 
        case (MotionEvent.ACTION_UP) : 
         Log.d("debug","Action was UP"); 
         break; 
        default: 
         break; 
       } 
       return true; 
      } 
     }); 

     mapView.getMapAsync(this); 
    } 

    @Override 
    public void onSaveInstanceState(Bundle outState) { 
     super.onSaveInstanceState(outState); 

     Bundle mapViewBundle = outState.getBundle(MAPVIEW_BUNDLE_KEY); 
     if (mapViewBundle == null) { 
      mapViewBundle = new Bundle(); 
      outState.putBundle(MAPVIEW_BUNDLE_KEY, mapViewBundle); 
     } 

     mapView.onSaveInstanceState(mapViewBundle); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     mapView.onResume(); 
    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     mapView.onStart(); 
    } 

    @Override 
    protected void onStop() { 
     super.onStop(); 
     mapView.onStop(); 
    } 

    @Override 
    protected void onPause() { 
     mapView.onPause(); 
     super.onPause(); 
    } 

    @Override 
    protected void onDestroy() { 
     mapView.onDestroy(); 
     super.onDestroy(); 
    } 

    @Override 
    public void onLowMemory() { 
     super.onLowMemory(); 
     mapView.onLowMemory(); 
    } 


    @Override 
    public void onMapReady(GoogleMap googleMap) { 

     map = googleMap; 
    } 
} 

왜 리스너가 호출되지 않습니다? 내가 도대체 ​​뭘 잘못하고있는 겁니까?

는 그것은 나에게 오류를주고 있기 때문에

임의의 넌센스 "는 게시물이 코드는 주로 것 같습니다"

+0

Mapviews에 TouchEvent를 추가 터치 리스너로 작업하십시오. 클릭 리스너를 사용하거나 [터치 이벤트를 가로 챌 수있는 방법을 만들 수 있습니다] (http://stackoverflow.com/questions/14013002/google-maps-android-api-v2-detect-touch-on-map) –

답변

0

MapView에 오버레이를 등록하고 있지 않은 것 같습니다 그

public void onCreate(Bundle savedInstanceStates){  
    super.onCreate(savedInstanceStates); 
    setContentView(R.layout.map); 

    MapView mapview=(MapView)findViewById(R.id.view_map); 

    mapOverlay myOverlay = new mapOverlay(); 
    List<Overlay> overlays = mMapView.getOverlays();   
    overlays.add(myOverlay); 
}   



class mapOverlay extends com.google.android.maps.Overlay{ 
    @Override 

    public boolean onTouchEvent(MotionEvent event, MapView mapview){ 

     switch (event.getAction()) { 

        case (MotionEvent.ACTION_DOWN) : 
         Log.d("debug","Action was DOWN"); 
         break; 
        case (MotionEvent.ACTION_MOVE) : 
         Log.d("debug","Action was MOVE"); 
         break; 
        case (MotionEvent.ACTION_UP) : 
         Log.d("debug","Action was UP"); 
         break; 
        default: 
         break; 
       } 
       return true; 
    } 
} 
+0

' 'Log.d ("debug", "Listener")''도 호출되지 않습니다. 문제는 청취자가 – Tirafesi

+0

라고 대답하지 않고 답변을 편집했기 때문입니다. – rafsanahmad007