2014-03-24 2 views
0
나는 구글 맵을 표시하려고

, 나는디스플레이 구글지도/활동

LocatorMap.java에 대한 나의 자바 클래스이다 .. 나는 내 문제가 어디에 즉 의심 많은 그래서 사용되는 조각를 havent :

<?xml version="1.0" encoding="utf-8"?> 
<com.google.android.gms.maps.MapView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/mapView" /> 

그리고이 같은 뷰 제시하는 것을 시도하고있다 :

public class LocatorMap extends Fragment { 

    MapView m; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     // inflat and return the layout 
     View v = inflater.inflate(R.layout.activity_locator_map, container, false); 
     m = (MapView) v.findViewById(R.id.mapView); 
     m.onCreate(savedInstanceState); 

     return v; 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     m.onResume(); 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     m.onPause(); 
    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
     m.onDestroy(); 
    } 

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

내 활동 XML은

을 나는이 작업을 수행 할 때

내가 얻을 :

Unable to instantiate activity ComponentInfo{my package name.LocatorMap} 

cannot cast to android.app.Activity

내가 무슨 일을하고 있는가?

답변

1
public class LocatorMap extends Fragment { 

그것 아닌 활동 클래스와 당신은 당신이 필요로하는 것은 당신이 조각을 추가 할 수있는 활동 레이아웃에서 컨테이너가

Intent intent = new Intent(getApplicationContext(), LocatorMap.class); 
startActivity(intent); 

사용할 수 없습니다.

더 많은 정보

http://developer.android.com/guide/components/fragments.html

일반적으로 컨테이너는 FrameLayout이다. id가 fragment_containerFrameLayout을 활동 xml에 추가하고 활동 클래스에 다음 코드를 추가하십시오.

LocatorMap newFragment = new LocatorMap() ; 
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
transaction.replace(R.id.fragment_container, newFragment); 
transaction.addToBackStack(null); // if you want fragment to be added to backstack 
transaction.commit(); 
+0

이 코드를 내 activiy 클래스의 onCreate 메서드에 넣을 수 있습니까? – BluGeni

+0

@BluGeni 예 가능합니다. – Raghunandan