2012-10-06 5 views
0

나는 scrollView 안에서 MapView를 사용하고 싶었습니다. 그렇게하면지도에 스크롤 문제가 생기고지도를 스크롤 할 때 전체 페이지가 스크롤됩니다. 이 문제에 대한 해결책을 여기에서 찾았습니다. MapView inside a ScrollView?
myMapView라는 클래스를 만들었습니다. 여기의 코드입니다 :
MapView에서 onTouchEvent 무시하기

package com.wikitude.example; 

import android.content.Context; 
import android.util.AttributeSet; 
import android.view.MotionEvent; 

import com.google.android.maps.MapView; 

public class myMapView extends MapView { 

    public myMapView(Context context, String apiKey) { 
     super(context, apiKey); 
     // TODO Auto-generated constructor stub 
    } 

    public myMapView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     // TODO Auto-generated constructor stub 
    } 

    public myMapView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     int action = ev.getAction(); 
     switch (action) { 
     case MotionEvent.ACTION_DOWN: 
      // Disallow ScrollView to intercept touch events. 
      this.getParent().requestDisallowInterceptTouchEvent(true); 
      break; 

     case MotionEvent.ACTION_UP: 
      // Allow ScrollView to intercept touch events. 
      this.getParent().requestDisallowInterceptTouchEvent(false); 
      break; 
     } 

     // Handle MapView's touch events. 
     super.onTouchEvent(ev); 
     return false; 
    } 
} 

하지만이처럼 내 MapActivity에서 사용하려고하면
Undable to start activity ComponentInfo{com.smtabatabaie.example/com.smtabatabaie.mainActivity}: java.lang.ClassCastException: com.google.android.maps.MapView :

myMapView myview = (myMapView) findViewById(R.id.themap); 

는이 오류가 발생합니다.
문제가있는 곳을 찾지 못했지만 문제가없는 것 같습니다. 누군가가 나를 도울 수 있으면 감사 할께.
감사합니다.

+0

무엇이 오류가 발생합니까? Logcat 오류 로그를 질문에 게시하십시오. –

+0

감사합니다 Vishwa, 나는 나의 질문을 편집하고 오류를 게시했습니다. – m0j1

답변

3

여기에 왜 그 ClassCastException이 발생하는지 설명합니다. 사용자 정의 맵뷰를 선언 한 XML 파일에서 실제로 사용자 정의 맵뷰의 이름을 선언해야합니다. 따라서 myMapView가 될 수 있습니다. 다음은 XML 파일의 모습입니다.

<com.wikitude.example.myMapView //This is where you're probably going wrong (so what I've posted is the right way to declare it) 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mapview" 
android:layout_width="fill_parent" //Replace these with whatever width and height you need 
android:layout_height="fill_parent" 
android:clickable="true" 
android:apiKey="Enter-your-key-here" 
/> 
+0

감사합니다. 그것은 정확하게 오류를 유발 한 문제였습니다. 고마워요 Vishwa;) – m0j1